Android 添加常駐圖標到狀態欄


 / *
     * 如果沒有從狀態欄中刪除ICON,且繼續調用addIconToStatusbar,則不會有任何變化.如果將notification中的resId設置不同的圖標,則會顯示不同的圖標
     * / 
    private void addIconToStatusbar(int resId){ 
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
        Notification n = new Notification();
        //常駐狀態欄的圖標
        n.icon = resId;
        // 將此通知放到通知欄的"Ongoing"即"正在運行"組中  
        n.flags |= Notification.FLAG_ONGOING_EVENT; 
        // 表明在點擊了通知欄中的"清除通知"后,此通知不清除, 經常與FLAG_ONGOING_EVENT一起使用  
        n.flags |= Notification.FLAG_NO_CLEAR;          
        PendingIntent pi = PendingIntent.getActivity(this, 0, getIntent(), 0); 
        n.contentIntent = pi; 
        n.setLatestEventInfo(this, getString(R.string.flow), "10M/30M", pi); 
        nm.notify(NOTIFICATION_ID_ICON, n); 
    } 

  private void deleteIconToStatusbar(){ 
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
        nm.cancel(NOTIFICATION_ID_ICON); 
    } 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM