android狀態列中多個通知衝突的問題

來源:互聯網
上載者:User

網上看到的解決辦法:

如果用相同的通知id, 該怎麼告訴處理通知的活動,每個通知的內容呢?
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
最後一個參數可以保證顯示的是最新的那個通知
如果用不同的通知id, 為什麼處理通知的活動得到的Intent總是第一個通知的Intent呢?
多個Intent是根據它們的Data屬性來區分的,如果Data相同,將認為是同一個Intent

 

實踐之後不是很好用,請教別人找到瞭解決辦法。

PendingIntent.getActivity(Context context, int requestCode,Intent intent, int flags)

requestCode 值如果一樣,就會出現多個通知都指向一個intent。

只要requestCode不一樣就可以解決問題了!

 

 

貼一段完整的代碼:下載完成後通知欄出現提示通知

 

/**
   * 狀態列訊息通知  下載完成
   * @param context
   * @param name
   */
  public static void notifyTaskFinishToStatusBar(Context context,String name)
     {
   String text;
  if(name!=null){
   text=name+context.getString(R.string.has_download);
  }else{
   text=context.getString(R.string.has_download);
  }   
   
  NotificationManager nfm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(R.drawable.icon, text,System.currentTimeMillis());
        notification.flags=Notification.FLAG_AUTO_CANCEL;//點擊自動清除通知
        Intent openintent = new Intent();
        openintent.setClass(context, MainActivity.class);
        Bundle data=new Bundle();
        data.putInt(Constants.BOOT_INDEX_TAG, MainActivity.downloadPageLoadedState);
        openintent.putExtras(data);
       
  PendingIntent contentIntent = PendingIntent.getActivity(context, 1, openintent, 0);
  
        notification.setLatestEventInfo(context, context.getString(R.string.qc_download_tip),text, contentIntent);
        nfm.notify(Constants.QC_DOWNLOAD_NOTIFY, notification);
     }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.