Android: Intent extras not received

If you have put extras to an intent and they are not received at the receiving activity, there could be 2 reasons..

1. The activity already exists in android backstack and the extras are not caught in onCreate() but they can be found in onNewIntent()

2. If the extras are passed with an activity of a PendingIntent, then as per the official documentation. http://developer.android.com/reference/android/app/PendingIntent.html. So, to pass the extras correctly, either you need to make sure each of the intents are having differentiation in terms of action, data, type, class, and categories. Or cancel the current PendingIntent if exists in the system by using FLAG_CANCEL_CURRENT or FLAG_UPDATE_CURRENT.

Happy Coding..

Advertisements

Android: Never miss on GCM ID tracking

I have come across an excellent blog regarding GCM tracking and in the mobile world, push is the only gateway for you to reach the user after the installation.So, we can’t afford to mess it up by not following some easy methods which ensure successful tracking of GCM ids. Please visit the following link for the entire details …

http://blog.pushbullet.com/2014/02/12/keeping-google-cloud-messaging-for-android-working-reliably-techincal-post/

Happy Coding…

Android: Center aligning a TextView with drawableLeft

Instead of using a TextView and ImageView, we can use drawables of TextView to reduce the no.of views used.

So, the problem at hand is, how do you align a TextView text and it’s left drawable to the center horizontally in a given width.

Fail Method: 

Put the textview width to “match_parent” and use “android:gravity” as center, the expected result is that both drawable and text should be center aligned horizontally, but to my surprise, i see only text horizontally aligned and the drawable is aligned to the textview left.

Working Method But Not Efficient:

Take a horizontal LinearLayout, put ImageView and TextView(no drawableLeft since we are using ImageView) in it with each of the view’s width set to “wrap_content”, and use “android:layout_gravity” to center on the LinearLayout. This works but we are using extra ImageView and LinearLayout.

Best Method:

Set TextView’s width to “wrap_content”, use drawableLeft,  and set “layout_gravity” to center for the TextView.

Happy Coding…

Android: How to find if a user has uninstalled the application

In the apps world, uninstall is a very common phenomenon, especially in Android, where there are no checks before an app gets published.

So how do you find if a particular user has uninstalled your application, a quick answer is GCM. Lets look at what happens when you send a push to a device where your application has been uninstalled.. (picked up from GCM docs)

  1. The end user uninstalls the application.
  2. Your server sends a message to GCM server.
  3. The GCM server sends the message to the device.
  4. The GCM client receives the message and queries Package Manager about whether there are broadcast receivers configured to receive it, which returns false.
  5. The GCM client informs the GCM server that the application was uninstalled.
  6. The GCM server marks the registration ID for deletion.
  7. The 3rd-party server sends a message to GCM.
  8. The GCM returns a NotRegistered error message to your server.
  9. Your server should delete the registration ID.

So from the above steps, it’s easy to understand that if your server gets “NotRegistered” error message, then the app has been uninstalled on the user’s device. So all you need to do is, send a silent push to your application, to check if it exists on user’s device.

Though from my personal experience, GCM server doesn’t return the error message even the app has been uninstalled, at least for the first few days of uninstallation.My guess is that GCM server takes some time to update the information of app uninstallation.

A more accurate approach will be to receive an ack from the application for the push message, So, if you receive an ack then the app still exists, if you don’t then the app doesn’t exist on the user’s device. But, there is a catch here, what if the app exists on the user’s device but the message is not delivered because the user isn’t connected with internet. How long will you wait to receive the ack, here is where your conscience comes to the rescue, you have to decide the time you will wait for the ack and decide if the app exists on user’s device. If your app is dependent on internet for the app usage and you don’t receive an ack with in 3-4 days, it’s safe to assume the user is useless to you whether he has the app or not, you can safely put him under uninstall category.

Identifying the uninstallation details can help you find some insights about the app if you can map user’s information with device information.

Happy Coding…