【发布时间】:2014-03-26 10:51:35
【问题描述】:
我正在尝试通过通知启动具有附加功能的应用。我得到它的启动意图:
Intent launchIntentForApp = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
注意:上下文属于同一个应用程序本身。我正在尝试构建一个可以在我的其他应用程序中使用的库。
我通过以下方式添加了一些额外内容:
launchIntentForApp.putExtra("test", true);
然后我为其创建一个待处理的 Intent,并将其添加到通知抽屉中:
PendingIntent pIntent = PendingIntent.getActivity(context, 0, launchIntentForApp, 0);
Notification n = new Notification.Builder(context)
.setContentTitle(notifTitle)
.setContentText(notifMessage)
.setContentIntent(pIntent)
.setAutoCancel(true)
.setStyle(new Notification.BigTextStyle()
.bigText(notifMessage))
.setSmallIcon(R.color.transparent)
.build();
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, n);
但是,当启动该应用程序的 Activity 时,在该 Activity 的 onCreate() 中,以下始终返回 null:
Bundle extras = getIntent().getExtras();
如何向该应用的主要活动发送额外信息?
【问题讨论】: