Notification的参数

来源:互联网 发布:windows系统怎么升级 编辑:程序博客网 时间:2024/06/05 15:58
 

项目开发中遇到以下问题,需要在一个Activity中显示不同的消息类型,消息通过notification触发,代码如下:

 

            Intent intent = new Intent(context,                    NotificationDetailsActivity.class);            intent.putExtra(PNConstants.NOTIFICATION_ID, notificationId);            intent.putExtra(PNConstants.NOTIFICATION_TITLE, title);            intent.putExtra(PNConstants.NOTIFICATION_MESSAGE, message);            intent.putExtra(PNConstants.NOTIFICATION_LOGIN_URI, loginUri);            intent.putExtra(PNConstants.NOTIFICATION_URI, uri);            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);            intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);            PendingIntent contentIntent = PendingIntent.getActivity(context, 0,                    intent, PendingIntent.FLAG_UPDATE_CURRENT);            notification.setLatestEventInfo(context, title, message,                    contentIntent);            notificationManager.notify(notificationId, notification);

 如此,在接收多条不同类型的消息后,打开不同消息,进入消息详细页面NotificationDetailsActivity显示的始终是最后一条消息内容,而不是根据消息类型分类显示各分类的最后一条。

 

 

为解决此问题有两种方法,但是没有找到合理的解释,先记录如下,

 

方法1:为intent添加不同的Action

 

intent.setAction(""+System.currentTimeMillis());
 

方法2:PendingIntent.getActivity的第二个参数设为消息类型notificationId,

 

PendingIntent contentIntent = PendingIntent.getActivity(context, notificationId, intent, PendingIntent
原创粉丝点击