我开发了一个基本的通知示例,并试图捕获点击的通知。但我不能。
我把一个arraylist放到了我的通知中,并通过添加额外内容将其传递给接收者活动,然后尝试抓住但是没办法!
无论如何都要抓住哪一个穿过?
答案 0 :(得分:4)
您可以将Bundle
和PendingIntent一起传递到下一个活动。
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);
}
我在这里使用杰克沃顿的NotificationCompat2,但答案并不依赖于此。