同时显示多个 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系统中, ...
随机推荐
- LaTeX新人教程,30分钟从全然陌生到基本入门
1.LaTeX软件的安装和使用 方法A(自助):在MikTeX的官网下载免费的MikTeX编译包并安装.下载WinEdt(收费)或TexMaker(免费)等编辑界面软件并安装. 方法B(打包):在 ...
- Cocos2dx中Plugin-X 在android下的整合
直接拉plugin-x中的jar包导入到Eclipse中就可以.用这么麻烦的工具干嘛.
- [计算机基础]URI与URL
URI : uniform resource identifier统一资源标示符用于指定Web资源的字符串,它定义了Web资源中的各个不同的部分.ex:http://example.org/absol ...
- 14.2.5.5 Change Buffer
14.2.5.5 Change Buffer change buffer是一个指定的数据结构 用于caches 数据到secondary index pages 当影响的pages 不是在buffer ...
- java中遍历MAP,嵌套map的几种方法
java中遍历MAP的几种方法 Map<String,String> map=new HashMap<String,String>(); map.put("us ...
- OCM读书笔记(2) - PL/SQL 基础
1. % type 用法,提取% type所在字段的类型 declare myid dept.deptno % type; myname dept.dname % type;begin ...
- Error: 17053 LogWriter: Operating system error 21(The device is not ready.)
今天在Detach数据库的时候出现错误,运行DBCC CHECKDB从SQL Server error log中看到下面的信息: Error: 17053, Severity: 16, State: ...
- Web API设计
Web API设计经验与总结 在移动互联网的时代, Web服务已经成为了异构系统之间的互联与集成的主要手段,各种 Web服务几乎都采用REST风格的Web Api来构建. 通过Http协议的形式来. ...
- Zeroonepack coming~^.^
今天抓的四道DP做完了==三道是用背包做的,突然想起来背包知识点总结还没做~反正时间还早..把01背包和完全背包小结了吧~~福利来啦~~噶呜~ 01背包: 基本思路: 01背包问题是最广为人知的动态规 ...
- Java模拟POST表单提交HttpClient操作
public static void Login() { String url = "http://www.***.com/login"; PostMethod postMetho ...