从带有数据的通知启动应用程序
我正在尝试使用 C2DM 在我的 Android 手机上触发推送通知,并让用户单击通知并在应用程序中启动特定活动。我如何传递这些信息?
目前我正在执行以下操作:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager
= (NotificationManager) getSystemService(ns);
int icon = R.drawable.notification23;
Notification notification = new Notification(icon, tickerText, when);
notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL;
Context appContext = getApplicationContext();
Intent notificationIntent = new Intent(this, RequestDialogActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.putExtra(LocationHandler.KEY_ORIGINATOR, number);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(appContext, contentTitle, contentText, contentIntent);
final int id = 1;
mNotificationManager.notify(id, notification);
我尝试通过在 notificationIntent 上调用 putExtra 来存储状态,但新活动始终具有 null savingInstanceState Bundle。我如何传递信息?
I'm trying to use C2DM to trigger a push notification on my android phone, and have the user click the notification and launch a certain activity in the app. How can I pass this information along?
Currently I'm doing the following:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager
= (NotificationManager) getSystemService(ns);
int icon = R.drawable.notification23;
Notification notification = new Notification(icon, tickerText, when);
notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL;
Context appContext = getApplicationContext();
Intent notificationIntent = new Intent(this, RequestDialogActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.putExtra(LocationHandler.KEY_ORIGINATOR, number);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(appContext, contentTitle, contentText, contentIntent);
final int id = 1;
mNotificationManager.notify(id, notification);
I'm trying to store state by calling putExtra
on the notificationIntent, but the new activity always has a null savedInstanceState Bundle. How can I pass information along?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在意图中设置的额外内容必须通过
getIntent().getExtras()
检索savedInsanceState
更多的是在应用程序关闭时检索状态系统并且您想要恢复用户上次看到的相同状态。the extras you set in the intent have to be retrieved by the
getIntent().getExtras()
thesavedInsanceState
is more about retrieve the state when the application have been closed by the system and you want to recover the same state that user saw last time.