同时显示多个 Notification
主要出在PendingIntent.getActivity();的第二个参数,API文档里虽然说是未被使用的参数(给出的例子也直接写0的),实际上是通过该参数来区别不同的Intent的,如果id相同,就会覆盖掉之前的Intent了。所以总是获取到最后一个Intent。
只要每个不同的Intent对应传递一个独立的ID就可以了,以上函数修改如下(增加ID参数):
package com.gf.messaging.implemention.handler; import org.json.JSONObject; import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast; import com.gf.messaging.MessagePushService;
import com.gf.messaging.MessagePushServiceConfig; public class NotificationHandler {
private static int NOTIFICATION_ID = 0x30001;//通知栏消息id
private MessagePushService mService;
private MessagePushServiceConfig mConfig; public NotificationHandler(MessagePushService service, MessagePushServiceConfig config){
mService = service;
mConfig = config;
} public void handleNotification(JSONObject jsonPayload) {
PushNotiInfo pni = ExplanationPushNoti.getPushNoti(jsonPayload);
String payload = jsonPayload.optJSONObject("data").optString("message");
NotificationManager notificationManager = (NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(
mConfig.iconId, payload, System
.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL; Intent launchIntent = new Intent("com.gf.messaging.QuotationWindow");//mConfig.intentAction
launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
launchIntent.putExtra("stock_code",
pni.code);
launchIntent.putExtra("stock_name",
pni.stockName);
String temp = pni.market;
if(temp.equals("sz"))
launchIntent.putExtra("stock_market",
1);
else
launchIntent.putExtra("stock_market",
0); PendingIntent pendingIntent = PendingIntent.getActivity(mService.getApplicationContext(),
NOTIFICATION_ID, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.contentIntent = pendingIntent;
notification.setLatestEventInfo(
mService.getApplicationContext(),
mConfig.notificationTitle, payload, pendingIntent); notificationManager.notify(NOTIFICATION_ID++,
notification); if(NOTIFICATION_ID == 10) notificationManager.cancel(NOTIFICATION_ID - 10);// 取消之前的通知消息; }
}
更多的移动互联网的发展趋势、app开发、移动互联网应用相关的资料请到互联网的一点事:www.yidin.net 留言
android QQ群:222392467
资料:
http://www.yidin.net/?p=8280
http://www.yidin.net/?p=9725
http://my.oschina.net/yidinshi/blog/133729
同时显示多个 Notification的更多相关文章
- 轻松让HTML5可以显示桌面通知Notification非常实用
使用Notification的流程 1.检查浏览器是否支持Notification2.检查浏览器的通知权限3.如果权限不够则申请获取权限4.创建消息通知5.展示消息通知 Notification AP ...
- [问题解决]同时显示多个Notification时PendingIntent的Intent被覆盖?
情况是这样的,使用NotificationManager触发多个Notification: private Notification genreNotification(Context context ...
- Notification状态栏显示信息
Notification即通知,用于在通知栏显示提示信息. 在API Level > 11,Notification类中的一些方法被Android声明deprecated(弃用),而在API L ...
- Android中使用Notification实现宽视图通知栏(Notification示例二)
Notification是在你的应用常规界面之外展示的消息.当app让系统发送一个消息的时候,消息首先以图表的形式显示在通知栏.要查看消息的详情需要进入通知抽屉(notificationdrawer) ...
- 安卓Notification的setLatestEventInfo is undefined出错不存在的解决
用最新版的SDK,在做状态栏通知时,使用了Notification的setLatestEventInfo(),结果提示: The method setLatestEventInfo(Context, ...
- android: Android Notification
Notification即通知,用于在通知栏显示提示信息. 在较新的版本中(API level > 11),Notification类中的一些方法被Android声明deprecated(弃用 ...
- 添加常驻Notification
private static final int NOTIFICATION_ID=250; //用来标示notification,通过notificatinomanager来发布同样标示的notifi ...
- 通知(Toast+Notification)
Toast简要说明:(前面已经用过好多次了) Toast是一种非持久的(在屏幕上面留一会儿就消失了),提供给用户简洁提示信息的视图. 它不阻断用户的操作,一般用于显示一些不重要的信息.(比方说设置音量 ...
- Android 状态栏通知Notification、NotificationManager简介
Notification(通知)一般用在电话,短信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提示用户处理这个通知,这时手从上方滑动状态栏就可以展开并处理这个通知: 在Android系统中, ...
随机推荐
- 临界段CCriticalSection的使用
类CCriticalSection的对象表示一个“临界区”,它是一个用于同步的对象,同一时刻仅仅同意一个线程存取资源或代码区.临界区在控制一次仅仅有一个线程改动数据或其他的控制资源时很实用.比如,在链 ...
- javascript (十二)对象二
JavaScript 中的所有事物都是对象:字符串.数字.数组.日期,等等. 在 JavaScript 中,对象是拥有属性和方法的数据. 属性和方法 属性是与对象相关的值. 方法是能够在对象上执行的动 ...
- 图解UML类与类之间的六中关系
大话设计模式上的一个图,我用EA画出来的: UML中的6大关系相关英文及音标: 依赖关系 dependency [di'pendənsi] 关联关系 association [ə,səuʃi' ...
- #pragma详解
在#Pragma是预处理指令它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作.#pragma指令对每个编译器给出了一个方法,在保持与C和C ++语言完全兼容的情况下,给出主机或操作系统专有 ...
- Delphi透明组件开发(去掉自己的csOpaque,去掉父控件的WS_CLIPCHILDREN,增加WS_EX_TRANSPARENT,截获WM_ERASEBKGND,然后在WM_DRAWITEM里画) good
透明的控件, 一般继承自TGraphicControl的(就是那些没有handle属性, 不能有focus的控件, 如image)都有Transparent属性. 对TWinControl类的控件, ...
- ORACLE 中的一些特殊符号
oracle通配符,运算符的使用 用于where比较条件的有: 等于:=.<.<=.>.>=.<> 包含:in.not in exists.not exists 范 ...
- drupal 7 模块开发,hook_form
因为不是系统学习,只能把每天自己学习到的东西零碎的记录下来. 一来方便自己记忆,二来可供大家查阅. 后续有精力再去做进一步的整理. 1 开发一个模块分为有下面几个文件 hook.admin.inc h ...
- Struts ActionForm简单理解
要想明确struts的控制流程以及它核心API的实现原理(比方 Action/DispatchAction/ActionForm的实现原理),玩转struts1.2的关键就是可以玩转 ActionFo ...
- Cordova/Phonegap 升级至 2.8.1
相关链接 Apache Cordova 项目首页: http://cordova.apache.org/ Apache Cordova 历史版本列表: http://archive.apache.or ...
- CheckBox和RadioButton以及RadioGroup
CheckBox:复选框 有两种状态 选中状态(true),未选状态(false) 属性 android:checked= "false"(表示该复选框未被选中) RadioGro ...