如何获得通知ID? [英] How to get notification id?

查看:133
本文介绍了如何获得通知ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个基本的通知示例,并试图捕获单击了哪个通知.但是我不能.

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

反正有没有赶上哪个人喜欢?

解决方案

您可以将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);
}

我在这里使用Jake Wharton的 NotificationCompat2 ,但答案并不取决于此.

i developed an basic notification example and tried to catch which notification clicked. But i couldnt.

I put an arraylist my notificaiton and pass it to reciever activity by putting extras, then try to catch but no way !

Are there anyway to catch which one cliked ?

解决方案

You can pass a Bundle along with PendingIntent to the next 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());

and the method 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);
}

I am using NotificationCompat2 by Jake Wharton here but the answer does not depend on that.

这篇关于如何获得通知ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆