zoukankan      html  css  js  c++  java
  • 同时显示多个 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
  • 相关阅读:
    【转载】零基础学Support Vector Machine(SVM)
    【转载】前向传播算法(Forward propagation)与反向传播算法(Back propagation)
    python 3.5 解决csv 读入中的'utf-8' codec can't decode办法
    pandas用法大全
    南阳理工OJ 题目168.房间安排问题与题目14.会场安排问题
    C++中IO设置数字精度问题
    C++中memset()函数笔记
    Java 编程命名规范
    数据类型内存分配--js基础
    对象--js基础
  • 原文地址:https://www.cnblogs.com/ondream/p/3179249.html
Copyright © 2011-2022 走看看