How to get notification id?

守給你的承諾、 提交于 2019-12-04 14:44:46

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/13593351/how-to-get-notification-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!