网上看到的解决办法:
如果用相同的通知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代码:
?
- /**?
- ???*?状态栏消息通知??下载完成?
- [email protected]?
- [email protected]?
- ???*/??
- ??public?static?void?notifyTaskFinishToStatusBar(Context?context,String?name)??
- ?????{??
- ???String?text;??
- ??if(name!=null){??
- ???text=name+context.getString(R.string.has_download);??
- ??}else{??
- ???text=context.getString(R.string.has_download);??
- ??}?????
- ?????
- ??NotificationManager?nfm?=?(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);??
- ????????Notification?notification?=?new?Notification(R.drawable.icon,?text,System.currentTimeMillis());??
- ????????notification.flags=Notification.FLAG_AUTO_CANCEL;//点击自动清除通知??
- ????????Intent?openintent?=?new?Intent();??
- ????????openintent.setClass(context,?MainActivity.class);??
- ????????Bundle?data=new?Bundle();??
- ????????data.putInt(Constants.BOOT_INDEX_TAG,?MainActivity.downloadPageLoadedState);??
- ????????openintent.putExtras(data);??
- ??????????
- ??PendingIntent?contentIntent?=?PendingIntent.getActivity(context,?1,?openintent,?0);??
- ????
- ????????notification.setLatestEventInfo(context,?context.getString(R.string.qc_download_tip),text,?contentIntent);??
- ????????nfm.notify(Constants.QC_DOWNLOAD_NOTIFY,?notification);??
- ?????}?