Jerome Dumilieu Jerome Dumilieu - 3 months ago 22
Android Question

Get Notification Title Android

How could I get the Notification Title of the notification ?

Here's my code :

-From Notification Service :

resultIntent= new Intent(NotificationService.this, StartNAFromNS.class);
resultIntent.putExtra(Intent.EXTRA_TITLE, underestood_name.replace("__", " "));


-From StartNAFromNS :

String text = this.getIntent().getStringExtra(Intent.EXTRA_TITLE);


When doing this with only 1 notification, I get the correct title. However, if my application sends 2 notifications, I will get the title of the second notification.

How could I get the proper notification title ?

FAT FAT
Answer Source

Notification id should be unique within your application.

If a notification with the same id has already been posted by your application and has not yet been canceled, it will be replaced by the updated information.

NotificationManager notiManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);    
notiManager.notify(UNIQUE_ID, notification);

If you are using PendingIntent.getActivity() method, use different requestCode for different notification:

Intent resultIntent= new Intent(NotificationService.this, StartNAFromNS.class);
resultIntent.putExtra(Intent.EXTRA_TITLE, underestood_name.replace("__", " "));    

PendingIntent pI = PendingIntent.getActivity(mContext, REQUEST_CODE, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);

Hope this will help!