標籤:
通知欄,對話方塊,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入門