Reputation: 3
I need to launch/open one installed apk in my device from a BroadcastReceiver.
Here is the code:
public class C2DMMessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.w("C2DM", "Message Receiver called");
if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
Log.w("C2DM", "Received message");
ComponentName toLaunch = new ComponentName("es.mypackage","es.mypackage.myapplication");
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(toLaunch);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
My device receives the broadcast but fails with an unexpected problem.
The code to launch other apk works fine in other part of the application.
Is possible to launch other application from a broadcast?
Thank you very much.
Upvotes: 0
Views: 1002
Reputation:
As per my experience , you can not start activity from the C2DM Receiver, I found work around for that, Create one service and start activity from that service, stop service after you start the activity.
Thank You,
Upvotes: 1