I am looking for the best way to notify a user that they need to install a package by handling the possibility of an external package not being found.
In this particular case I am wishing to implement the TODO: if intent not found, notification on need to have GSF in the C2DMMessaging class
public static void register(Context context,
String senderId) {
Intent registrationIntent = new Intent(REQUEST_REGISTRATION_INTENT);
registrationIntent.setPackage(GSF_PACKAGE);
registrationIntent.putExtra(EXTRA_APPLICATION_PENDING_INTENT,
PendingIntent.getBroadcast(context, 0, new Intent(), 0));
registrationIntent.putExtra(EXTRA_SENDER, senderId);
context.startService(registrationIntent);
// TODO: if intent not found, notification on need to have GSF
}
I’m thinking that I should look for the error W/ActivityManager( 60): Unable to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gsf (has extras) }: not found
But how to trap that error?
UPDATE – Just found that the call to startService returns a ComponentName instance which is null if the service failed to start so my code now looks like this
ComponentName name = context.startService(registrationIntent);
// TODO: if intent not found, notification on need to have GSF
if(name == null){
Util.log_debug_message("@@@@ REG INTENT FAILED");
}else{
Util.log_debug_message("@@@@ REG INTENT SUCCEEDED");
}
(For anyone looking for this solution Util.log_debug is just a function I created in a util class to call Log.d so just replace this with a call to Log.d)
Which seems to work just fine so I guess I need to send a broadcast message with an extra to indicate the package needs to be installed. The receiver could then show an alert dialog explaining that the user must install!
What does the user need to install? and how would the user install whatever is needed to be installed?
Thanks in advance for any tips, pointers code snippets and help
I have resolved this issue – In the activity that calls the C2DM registration event I have this code
and I changed the C2DMessaging.register to a boolean method and added the check to ensure that the service started like so…