[android] notification入門

來源:互聯網
上載者:User

標籤:

通知欄,對話方塊,Toast是我們接觸的三個提示框,通知欄是在系統的應用com.adnroid.systemui當中的

 

接觸的幾個Manger,getSystemService()方法得到的,參數:

ACTIVITY_SERVICE,LAYOUT_INFLATER_SERVIC,TELEPHONY_SERVICE,

 

擷取NotificationManager對象,通過getSystemService()方法,參數:NOTIFICATION_SERVICE

調用NotificationManager對象的notify()方法,發送通知,參數:id是0,Notification對象

擷取Builder對象,通過new Notification.Builder()

調用Builder對象的setContentTitle() setContentText() setSmallIcon()  setLargeIcon()

setLargeIcon的參數:Bitmap對象,BitmapFactory.decodeResource(),參數:getResoure(),資源id

調用Builder對象的build()方法,得到Notification對象

此時會報一些錯誤,最低相容版本是11,我們直接加一個注釋屏蔽掉錯誤”NewApi”

 

在低版本的手機上,上面的代碼會出錯

擷取Notification對象,通過new出來,參數:資源id,文本,時間

調用Notification對象的setLastEventInfo()方法,設定最新訊息,參數:上下文,文本,PendingIntent對象

 

設定Notification對象的flags屬性為Notification.FLAG_AUTO_CANCEL 自動關閉

PendingIntent對象,通過PendingIntent的getActivity()方法,擷取到PendingIntent對象

6.0 版本移除了Notification.setLatestEventInfo()方法

流氓軟體會使用這來彈廣告,我們可以進系統應用設定,勾掉顯示通知

[android] 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.