加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 获取通知标题Android

发布时间:2020-12-15 04:38:08 所属栏目:Java 来源:网络整理
导读:我如何获得通知的通知标题? 这是我的代码: – 从通知服务: resultIntent= new Intent(NotificationService.this,StartNAFromNS.class); resultIntent.putExtra(Intent.EXTRA_TITLE,underestood_name.replace("__"," ")); – 从StartNAFromNS: String tex
我如何获得通知的通知标题?

这是我的代码:

– 从通知服务:

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

– 从StartNAFromNS:

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

当只有1个通知这样做时,我得到正确的标题.但是,如果我的应用程序发送了2个通知,我将获得第二个通知的标题.

我怎样才能获得正确的通知标题?

解决方法

通知ID在您的应用程序中应该是唯一的.

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);

如果您使用的是PendingIntent.getActivity()方法,请对不同的通知使用不同的requestCode:

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);

希望这会有所帮助!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读