Getting Ionic framework running on Ubuntu

Very frustrating when it appears that Ionic setup is as simple as http://ionicframework.com/getting-started/ to get a helloworld running. But I received all kinds of errors when following those simple instructions. Primarily, there were Cordova dependencies that were missing and are not installed if you only follow Ionic instructions.

So here they are. After installing cordova and ionic

sudo npm install -g cordova

sudo npm install -g ionic

Install ADT

http://developer.android.com/sdk/index.html#download

Unzip to somewhere that makes sense for you on your home dir

Add paths

edit your .bashrc and add this to the bottom

export PATH=$PATH:/[path to adt]/adt-bundle/sdk/platform-tools:/[path to adt]/adt-bundle/sdk/tools

Save your .bashrc then run

source ~/.bashrc

Then install ant

sudo apt-get install ant

Then create a AVD

android create avd -n <name> -t <targetID>

you can list targets to see what you have available

android list targets

Now that everything else is installed and an AVD is created, you can continue with the Ionic instructions.

$ cd myApp
$ ionic platform android
$ ionic emulate android
$ ionic run android <-- still getting an error on this one

 


	

How To Keep An Android Service Running

How to keep an Android service running? This is kind of a trick question as the best practice is to not keep an Android service running. If you need to have something done continuously by your app via a service, the service should be started by an AlarmManager at a regular interval and kills itself after the task is done. The reason for this is that a long running service on Android is up to the OS to determine priority and in some cases would stop running. By using this methodology, you are treading lightly since the service does not stay in memory.

Here is some sample code.

Service implementation

public class HeartBeat extends Service {

	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onStart(Intent i, int startId) {

		this.beat.run();
		this.stopSelf();
	}

	public Runnable beat = new Runnable() {

		public void run() {
                    // Do something
		}
	};
}

The AlarmManager that starts it.


			Intent iHeartBeatService = new Intent(this, HeartBeat.class);
			PendingIntent piHeartBeatService = PendingIntent.getService(this, 0, iHeartBeatService, PendingIntent.FLAG_UPDATE_CURRENT);
			AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
			alarmManager.cancel(piHeartBeatService);
			alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000, piHeartBeatService);

Now the heartbeat service will start every second and do something and kill itself.

Android making https requests with SSL from GoDaddy – No peer certificate error

Another hair pulling session that all ended well.

Task:

Make a secure call to a server using a httprequest and get the httpresponse for further processing.

Android http request and response:

HttpClient client = new DefaultHttpClient();
HttpGet req = new HttpGet("https://www.example.com");
HttpResponse res = client.execute(req);

Error:

javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

Problem:

The issue is that cert from GoDaddy was installed but not installed completely. An Intermediate cert is required for the server/domain in order to have a fully installed cert.

Reference:

http://community.godaddy.com/help/5238

Second Android phone, Agora, follows G1

It has been less than two months after G1, the first Android phone, was launch that the second one is announced by Kogan.  It is the Agora, a phone looking more like a Blackberry than an iPhone.  The great thing about this new phone is that it is not locked.  However, it does not have as many features as the G1.

Here is what Howard Wong has to say about the Agora vs G1.

This is more blackberry-ish in style, slimmer and so in a way its a bit more “humble” and makes you wanna compare it to a blackberry.. which sort of allows Agora to scale back on memory features (256 meg, 128 meg flash, no WIFI).  Also I think they were smarter about battery life by supplying a 1300mAh battery as opposed to G1’s 1150mAh.. G1 most prolly uses more power anyway.  Clearly Agora’s niche is to bridge mainstream PDA users to Android.. a very smart move because quite frankly, most people don’t know or care about where mobile applications come from. I believe this phone to be a much more humbler/accessible stage to feature android apps.

Looking back, I think Tmobile should’ve released something like this and steared clear of IPhone envy.  One of the first things I said to myself when I first played with the G1 was, “I can’t believe google allowed this to be the first phone.”

I still think the 4 buttons should be electro-sensitive like the touchscreen.  For such mainstay controls, they deserve to be on par with the touchscreen.  At least with this new Agora phone I won’t complain because interaction through the touchscreen seems more like a bonus whereas on the G1, it seems required.

Getting Android emulator working with Google Maps API Key

I was trying to get an Android app that uses Google Maps API to display a MapView running on the emulator.  It took quite a bit of hair pulling to finally get it working.

First, I tried using a self-signed keystore instead of the the debug.keystore provided through the Android SDK.  I created my keystore using keytool -genkey from JDK.  Then I switch the app from using the default, debug.keystore, to my-new-self-signed.keystore.  Using keytool -list, I got the MD5 of the certificate that is needed to obtain a Google Map API key.  Then the API key was put into the MapView android:apikey attribute.  When I brought up the app in the emulator, I got a blank map grid screen.  The reason I wanted to use the self-signed keystore instead of the debug keystore is so I don’t have to obtain a new Map API key and change the code to reflect this upon releasing the app.

So, I decided to go with the debug.keystore and that worked fine.  Here is what I had to do.

  1. $ keytool -list -alias androiddebugkey -keystore <path_to_debug_keystore>.keystore -storepass android -keypass android
  2. Copy that MD5 and goto http://code.google.com/android/maps-api-signup.html
  3. Signup for an API key
  4. In my xml file that has the views for the activity, add
    <com.google.android.maps.MapView
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:enabled="true"
     android:clickable="true"
     android:apiKey="example_Maps_ApiKey_String"
     />
  5. In the Manifest.xml file, add the permissions needed
    <uses-permission android:name=”android.permission.INTERNET”></uses-permission>
    <uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION”></uses-permission>
  6. In the Manifest.xml file, add the maps library
    <uses-library android:name=”com.google.android.maps” />
    within the application tag
  7. The entire Manifest.xml looks like this
    <?xml version=”1.0″ encoding=”utf-8″?>
    <manifest xmlns:android=”http://schemas.android.com/apk/res/android”
    package=”com.informationideas.mapapp”
    android:versionCode=”1″
    android:versionName=”1.0.0″>
    <uses-permission android:name=”android.permission.INTERNET”></uses-permission>
    <uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION”></uses-permission>
    <application android:icon=”@drawable/icon” android:label=”@string/app_name”>
    <uses-library android:name=”com.google.android.maps” />
    <activity android:name=”.ShowDesktop”
    android:label=”@string/app_name”>
    <intent-filter>
    <action android:name=”android.intent.action.MAIN” />
    <category android:name=”android.intent.category.LAUNCHER” />
    </intent-filter>
    </activity>
    </application>
    </manifest>
  8. The default activity file should look like this

    package com.informationideas.mapapp;
    import android.os.Bundle;
    import com.google.android.maps.MapActivity;

    public class ShowDesktop extends MapActivity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    }

    @Override
    protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
    }
    }

Now off to building cool things with the map!