我开发了一个基本的通知示例,并试图捕获点击的通知。但我不能。如何获取通知ID?
我把一个arraylist我的notificaiton并通过放置extras,然后试图捕捉,但没有办法通过它接收活动!
无论如何要抓住哪一个?
我开发了一个基本的通知示例,并试图捕获点击的通知。但我不能。如何获取通知ID?
我把一个arraylist我的notificaiton并通过放置extras,然后试图捕捉,但没有办法通过它接收活动!
无论如何要抓住哪一个?
您可以沿的PendingIntent传递Bundle
下一个活动。
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由杰克沃顿在这里,但答案并不取决于这一点。
谢谢,但这不是我所需要的。我需要捕获点击的通知。例如,如果我点击发件人3,它会敬酒发件人3点击。 – Talha
@talhakosen您可以从_YourNextActivity.class_中将Toast作为字符串捆绑到传递给该活动的信息_sender3_中。 –
我们可以为服装通知做到这一点,我使用的是远程视图。只是我需要更新从muiltiple通知具体通知。请参阅此链接http://stackoverflow.com/questions/27169367/android-update-specific-notification-from-multiple-notifications-which-have-rem –
我们可以看看你的源代码吗? –