【发布时间】:2015-11-12 23:19:02
【问题描述】:
我开发了一个基本的通知示例,并试图捕捉点击了哪个通知。但我不能。
我在我的通知中放置了一个数组列表,并通过添加附加信息将其传递给接收者活动,然后尝试捕捉但没有办法!
有没有办法捕捉到点击了哪一个?
【问题讨论】:
-
我们可以看看你的源代码吗?
标签: android android-notifications
我开发了一个基本的通知示例,并试图捕捉点击了哪个通知。但我不能。
我在我的通知中放置了一个数组列表,并通过添加附加信息将其传递给接收者活动,然后尝试捕捉但没有办法!
有没有办法捕捉到点击了哪一个?
【问题讨论】:
标签: android android-notifications
您可以将 Bundle 与 PendingIntent 一起传递给下一个 Activity。
Bundle bundle = new Bundle();
bundle.putString("Any String");
NotificationManager notifManager = (NotificationManager) this.getSystemService(this.NOTIFICATION_SERVICE);
int uniqueInteger = //create a unique Integer
int icon = R.drawable.ic_launcher;
NotificationCompat2.Builder mNotification = new NotificationCompat2.Builder(this).setSmallIcon(icon)
.setContentTitle(contentTitle).setContentIntent(getPendingIntent(bundle, uniqueInteger));
mNotification.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
mNotification.setAutoCancel(true);
notifManager.notify(uniqueInteger, mNotification.build());
和方法getPendingIntent()
private PendingIntent getPendingIntent(Bunble bundle, int rc) {
Intent notificationIntent = new Intent(this, YourNextActivity.class);
notificationIntent.putExtras(bundle);
return PendingIntent.getActivity(this, rc, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
我在这里使用的是 Jake Wharton 的 NotificationCompat2,但答案并不取决于此。
【讨论】: