1、notifcation要显示多条,那么NotificationManager.notify( id, notify);  中的要保持不一样;

如果id值一样,那么就把之前的notify覆盖更新为当期最新的;

2、点击notification 进入到activity, 使用到pendingIntent类方法,PengdingIntent.getActivity()的第二个参数,即请求参数,

实际上是通过该参数来区别不同的Intent的,如果id相同,就会覆盖掉之前的Intent了,

 

只要每个不同的Intent对应传递一个独立的ID就可以,实现每个Notification点击进入对应的activity中:

Java代码  
  1. private Notification genreNotification(Context context, int icon, String tickerText, String title, String content, Intent intent, int id){  
  2.         Notification notification = new Notification(icon, tickerText, System.currentTimeMillis());  
  3.         // 问题就在这里的id了  
  4.         PendingIntent pendIntent = PendingIntent.getActivity(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);  
  5. // 使用了原始布局
  6.         notification.setLatestEventInfo(context, title, content, pendIntent);  
  7.         notification.flags |= Notification.FLAG_AUTO_CANCEL;  
  8.         return notification;  
  9.     }  
  10.   
  11. ...  
  12. mNotificationManager.notify(ID_1,   
  13.                     genreNotification(mContext, ICON_RES,   
  14.                             notifyText1, notifyTitle1, notifyText1, intent_1, ID_1));  
  15. ...  
  16. mNotificationManager.notify(ID_2,   
  17.                     genreNotification(mContext, ICON_RES,   
  18.                             notifyText2, notifyTitle2, notifyText2, intent_2, ID_2));  
  19.   
  20. ...  
  21. mNotificationManager.notify(ID_3,   
  22.                     genreNotification(mContext, ICON_RES,   
  23.                             notifyText3, notifyTitle3, notifyText3, intent_3, ID_3));  

3、notification使用自定义布局: notification = new Notification(R.drawable.app_icon, content,
System.currentTimeMillis());
notification.defaults = Notification.DEFAULT_ALL; // 使用默认设置,比如铃声、震动、闪灯
notification.flags = Notification.FLAG_AUTO_CANCEL; // 但用户点击消息后,消息自动在通知栏自动消失
notification.flags |= Notification.FLAG_NO_CLEAR;// 点击通知栏的删除,消息不会依然不会被删除


Intent intent = new Intent(ctx, ContentNotifyActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP);

intent.putExtra("content", content);
intent.putExtra("number", title);
intent.putExtra("date", date);
intent.putExtra("title", title);
RemoteViews remoteView = PushApplication.getInstance()
.getRemoteViewsView();
remoteView.setImageViewResource(R.id.notification_icon,
R.drawable.app_icon);
//标题
remoteView.setTextViewText(R.id.notification_title, title);
//内容
remoteView.setTextViewText(R.id.notification_content, content);
// 设置notification的contentView为 remoteView
notification.contentView = remoteView;


pi = PendingIntent.getActivity(ctx, NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);

// 原始样式
// notification.setLatestEventInfo(ctx, title, content, pi);


notification.contentIntent = pi;

// 将消息推送到状态栏
manager.notify(NOTIFICATION_ID++, notification);

更多相关文章

  1. android Bundle saveInsanceState
  2. 一段android跳转到web界面的代码
  3. Android(安卓)Studio 单元测试之简单版
  4. Android中Junit测试、XML的序列化与解析
  5. Android(安卓)studio安装与配置Butter knife过程
  6. Android(安卓)程序安装地址问题
  7. textview点击后selector的pressed无效果
  8. Android使用ListView构造复杂页面,并响应点击事件,通过intent跳转
  9. Android(安卓)X86 Android-x86入门之--让你的Android-x86竖屏起

随机推荐

  1. android 打包时报错解决
  2. Android类似朋友圈评论视图Dialog实现
  3. Binder驱动之Buffer Size
  4. fragment和radiobutton做出类tabhost效果
  5. Android自定义view贝塞尔曲线
  6. ViewPager+PagerTabStrip实现页面选项卡
  7. android studio 2.x 升级到3.0之后 andro
  8. Android(安卓)N的铃声问题(2)
  9. Android动态获取U盘路径
  10. Android(安卓)银行卡扫描识别获取卡号