Tuesday, January 29, 2013

Android notification manifest configuration

Recently I had to add a notification to an existing Android 2.3.3 project. I followed the nice tutorial from mobiForge but was unable to get my notification to work properly. It would display in the notification bar but when I clicked on the notification nothing happened.

The cause of my problem turned out to be a missing intent-filter definition in my AndroidManifest.xml file. This is essential: the Activity to be launched by the notification must contain an intent-filter with action and category property settings.

Here is the AndroidManifest entry from the mobiForge tutorial for the activity (AlarmDetails) that is launched by the notification.  If the intent-filter entry is missing, AlarmDetails does not start when the notification is clicked.

<activity android:name=".AlarmDetails" android:exported="false" 

    android:label="Details of the alarm">

    <intent-filter>

        <action android:name="net.learn2develop.AlarmDetails"/>

        <category android:name="android.intent.category.DEFAULT"/> 

    </intent-filter>

</activity>


Thursday, January 17, 2013

Android web service issue caused by targetSDK change

Yesterday I wrapped up some code changes to an older Android app that had its original minSdkVersion set to 4 and no targetSdkVersion set.  The app makes numerous web service calls.

The updated application had been tested successfully on a Galaxy Tab running 4.2, a Motorola DroidX running 2.2 and numerous emulators running 4.2 or 2.2.  Therefore I updated the minSdkVersion to 8 and the targetSdkVersion to 17, then tested again on the same devices and emulators.

An end-user with a Nexus 7 running 4.2 immediately encountered an Internet connectivity problem.  Further testing determined the following:
  • Setting the targetSdkVersion back to 8 fixed the problem on the Nexus 7
  • The root source of the problem is the app makes web service calls on the main thread, which was allowable under Android 1.6 (4) when the app was originally developed.  This policy changed somewhere between SDK 8 and 17.  The key error message in the stack trace was: android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
 There are numerous examples online describing the correct way to do web service calls, here is one nice example.

Tuesday, January 15, 2013

Enable blog editor with Google 2-step verification

I have neglected my blog for too long so I decided to rename and overhaul my site and get blogging!  I selected MarsEdit for my new offline editor and immediately hit a snag - it would not accept my Google account credentials.

Turns out the root of this problem is I have Google's 2-step verification enabled on my account.  The solution is straightforward:

  1. Open Gmail
  2. Gear wheel > Settings > Accounts and Import > Other Google Account Settings > Security
  3. Click the Settings button under the 2-Step Verification section
  4. Manage Application Passwords
  5. Entered MarsEdit as the application name, generated a password, and then used that password during the MarsEdit setup process

Thanks to David Herron's post for the solution to this issue!