当前位置: 代码迷 >> Android >> android状态栏中多个通知冲突的有关问题
  详细解决方案

android状态栏中多个通知冲突的有关问题

热度:4   发布时间:2016-05-01 13:41:30.0
android状态栏中多个通知冲突的问题

网上看到的解决办法:

如果用相同的通知id, 该怎么告诉处理通知的活动,每个通知的内容呢?
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
最后一个参数可以保证显示的是最新的那个通知
如果用不同的通知id, 为什么处理通知的活动得到的Intent总是第一个通知的Intent呢?
多个Intent是根据它们的Data属性来区分的,如果Data相同,将认为是同一个Intent?

?

实践之后不是很好用,请教别人找到了解决办法。

PendingIntent.getActivity(Context?context, int requestCode,Intent?intent, int flags)

requestCode 值如果一样,就会出现多个通知都指向一个intent。

只要requestCode不一样就可以解决问题了!

?

?

贴一段完整的代码:下载完成后通知栏出现提示通知

?java代码:

?

[java] view plaincopy
  1. /**?
  2. ???*?状态栏消息通知??下载完成?
  3. [email protected]?
  4. [email protected]?
  5. ???*/??
  6. ??public?static?void?notifyTaskFinishToStatusBar(Context?context,String?name)??
  7. ?????{??
  8. ???String?text;??
  9. ??if(name!=null){??
  10. ???text=name+context.getString(R.string.has_download);??
  11. ??}else{??
  12. ???text=context.getString(R.string.has_download);??
  13. ??}?????
  14. ?????
  15. ??NotificationManager?nfm?=?(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);??
  16. ????????Notification?notification?=?new?Notification(R.drawable.icon,?text,System.currentTimeMillis());??
  17. ????????notification.flags=Notification.FLAG_AUTO_CANCEL;//点击自动清除通知??
  18. ????????Intent?openintent?=?new?Intent();??
  19. ????????openintent.setClass(context,?MainActivity.class);??
  20. ????????Bundle?data=new?Bundle();??
  21. ????????data.putInt(Constants.BOOT_INDEX_TAG,?MainActivity.downloadPageLoadedState);??
  22. ????????openintent.putExtras(data);??
  23. ??????????
  24. ??PendingIntent?contentIntent?=?PendingIntent.getActivity(context,?1,?openintent,?0);??
  25. ????
  26. ????????notification.setLatestEventInfo(context,?context.getString(R.string.qc_download_tip),text,?contentIntent);??
  27. ????????nfm.notify(Constants.QC_DOWNLOAD_NOTIFY,?notification);??
  28. ?????}?
  相关解决方案