同时显示多个 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系统中, ...
随机推荐
- javascript (十四) dom
通过 HTML DOM,可访问 JavaScript HTML 文档的所有元素. HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object M ...
- Lucene.Net 2.3.1开发介绍 —— 二、分词(五)
原文:Lucene.Net 2.3.1开发介绍 -- 二.分词(五) 2.1.3 二元分词 上一节通过变换查询表达式满足了需求,但是在实际应用中,如果那样查询,会出现另外一个问题,因为,那样搜索,是只 ...
- 开源免费跨平台opengl opencv webgl gtk blender, opengl贴图程序
三维图形的这是opengl的强项,大型3D游戏都会把它作为首选.图像处理,是opencv的锁定的目标,大多都是C的api,也有少部分是C++的,工业图像表现,图像识别,都会考虑opencv的.webg ...
- Data Recovery Advisor(数据恢复顾问)
Data Recovery Advisor 是11g新特性,是Oracle顾问程序架构的一部分,它会在遇到错误时自动收集有关故障信息.如果主动运行Data Recovery Advisor,通常可以在 ...
- Delphi动态申请数组内存的方法(不使用SetLength,采用和C相似的方式)
procedure TForm1.Button1Click(Sender: TObject);type TArr = array [0..0] of Integer; PArr = ^TArr;v ...
- php 写session
function do_login(){ //获取用户名和密码信息,和数据库中比对 echo 111111111; dump($_POST); dump($_SESSION); echo 222222 ...
- 使用VC++压缩解压缩文件夹
前言 项目中要用到一个压缩解压缩的模块, 看了很多文章和源代码, 都不是很称心, 现在把我自己实现的代码和大家分享. 要求: 1.使用Unicode(支持中文). 2.使用源代码.(不使用静态或 ...
- hdu 3832 Earth Hour (最短路变形)
Earth Hour Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Tota ...
- java特权制度设计篇
数据库表设计 1.1.1. 模块管理(jk_module) 项 类型 说明 id long 就是数据库记录idx号 name string 模块名称 orderid int 排序id 由小到大显 ...
- password加密问题
password加密问题 个人信息:就读于燕大本科软件project专业 眼下大三; 本人博客:google搜索"cqs_2012"就可以; 个人爱好:酷爱数据结构和算法,希望将来 ...