Android – get notification title
•
Java
How do I get the title of the notification?
This is 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 there is only one notification to do so, I get the correct title However, if my application sends 2 notifications, I will get the title of the second notification
How can I get the correct notification title?
Solution
The notification ID should be unique in your application
notificationmanager notiManager = (notificationmanager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); notiManager.notify(UNIQUE_ID,notification);
If you are using pendingintent Getactivity () method, please use different requestcodes for different Notifications:
Intent resultIntent= new Intent(NotificationService.this,StartNAFromNS.class); resultIntent.putExtra(Intent.EXTRA_TITLE," ")); PendingIntent pI = PendingIntent.getActivity(mContext,REQUEST_CODE,resultIntent,PendingIntent.FLAG_UPDATE_CURRENT);
I hope this will help!
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码