【问题标题】:How to get notification id?如何获取通知ID?
【发布时间】:2015-11-12 23:19:02
【问题描述】:

我开发了一个基本的通知示例,并试图捕捉点击了哪个通知。但我不能。

我在我的通知中放置了一个数组列表,并通过添加附加信息将其传递给接收者活动,然后尝试捕捉但没有办法!

有没有办法捕捉到点击了哪一个?

【问题讨论】:

  • 我们可以看看你的源代码吗?

标签: android android-notifications


【解决方案1】:

您可以将 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,但答案并不取决于此。

【讨论】:

  • 谢谢,但这不是我需要的。我需要捕捉点击了哪个通知。例如,如果我单击发件人 3,它将为单击发件人 3 敬酒。
  • @talhakosen 您可以从 YourNextActivity.class 发起 Toast,并将信息 sender3 作为捆绑包中的字符串传递给活动。
  • 我们可以为服装通知准确地做到这一点,我使用了remoteview。只是我需要从多个通知更新特定通知。请参阅此链接stackoverflow.com/questions/27169367/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-12-06
  • 2012-10-10
  • 2013-03-13
  • 2018-11-14
  • 1970-01-01
  • 2021-05-13
  • 1970-01-01
相关资源
最近更新 更多