1

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 ?

enter image description here

Talha
  • 12,673
  • 5
  • 49
  • 68

1 Answers1

4

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.

Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166
  • Thank you but it is not what i need. I need to catch which notification clicked. For example if i click sender 3, it will toast sender3 clicked. – Talha Nov 28 '12 at 07:32
  • @talhakosen You can raise a Toast from _YourNextActivity.class_ with the information _sender3_ passed to the activity as a String the bundle. – Gaurav Agarwal Nov 28 '12 at 10:57
  • Can we do that exactly for costume notification, where i used remoteview. just i need to update the specific notification from muiltiple notification .see this link http://stackoverflow.com/questions/27169367/android-update-specific-notification-from-multiple-notifications-which-have-rem – Mayur Raval Nov 27 '14 at 11:54