同时显示多个 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系统中, ...
随机推荐
- jquery动态改变背景颜色插件
GETHUB下载地址 背景颜色用animate方法时时无法改变颜色的 所以要使用插件进行补充. 用法: <!DOCTYPE html> <html> <head> ...
- perl的一些基本用法
ReadLine support available (try 'install Bundle::CPAN')cpan>进入cpan的shell,好了,我为了安装spamassassin,需要安 ...
- 改动Oracle GoldenGate(ogg)各个进程的读检查点和写检查点
请注意:请谨慎改动Oracle GoldenGate(ogg)各个进程的读检查点和写检查点. 请确保已经 掌握 ogg 各个进程的读检查点和写检查点的详细含义. BEGIN {NOW | yyyy-m ...
- Gradle学习之使用java plugin
请通过下面方式下载本系列文章的Github演示样例代码: git clone https://github.com/davenkin/gradle-learning.git Gradle最 ...
- CentOS6-釋放ip重新分配,centos7 ifconifg没有ip
http://bbs.csdn.net/topics/390725823 系统win7 ,dhcp自动获取ip虚拟机是10.0 安装之后我装了ubuntu 选用 NAT网络, 刚装完我能上网 ,但是 ...
- 解决CentOS无法显示中文字体 | 系统运维 | Web2.0
解决CentOS无法显示中文字体 | 系统运维 | Web2.0 About Me 博客园 devops 前端 张家港水蜜桃 傍晚好! 2013年09月12日 17:56:08 ...
- CF 316C2(Tidying Up-二分图最大边权)
C2. Tidying Up time limit per test 4 seconds memory limit per test 256 megabytes input standard inpu ...
- HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)
50 years, 50 colors Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons ...
- poj 2513 连接火柴 字典树+欧拉通路 好题
Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 27134 Accepted: 7186 ...
- Java面向对象基础二
1.对象的用法 2.多对象的创建方法 3.匿名对象的创建和用法