1

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

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

反正有没有抓住哪一个?

在此处输入图像描述

4

1 回答 1

4

您可以将 aBundle与 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,但答案并不依赖于此。

于 2012-11-27T22:31:18.943 回答