通知欄,對話框,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()方法
流氓軟體會使用這來彈廣告,我們可以進系統應用設定,勾掉顯示通知