收到GCM通知时启动应用程序

jas*_*ery 5 android android-intent android-c2dm google-cloud-messaging

我有GCM通知实施.我知道客户端应用程序会收到通知,无论它是处于前台,后台还是被杀死状态.我想知道的是,当应用程序处于被杀死状态时,如何在收到通知时启动我的应用程序?

jas*_*ery 5

在消息接收器中,我执行以下操作:

final Intent notificationIntent = new Intent(context, YourActivity.class);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Run Code Online (Sandbox Code Playgroud)

这里用条目活动替换YourActivity.class.这对我有用.

  • 如果应用程序已经运行怎么办? (2认同)