最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 通知的基本用法示例代碼

 更新時(shí)間:2016年08月12日 08:46:26   投稿:lqh  
本文主要介紹Android 通知欄,這里整理了相關(guān)的知識(shí)資料,并附示例代碼和詳解,有需要的小伙伴可以參考下

寫android通知的時(shí)候發(fā)現(xiàn)Notification的setLatestEventInfo被棄用,于是搜素并整理了一下新的android通知的基本用法。

一、獲取NotificationManager實(shí)例

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

二、創(chuàng)建Notification實(shí)例

在這里需要根據(jù)project的min-sdk來選擇實(shí)現(xiàn)方法,MIN API Level < 11的可以使用setLatestEventInfo()方法,以下介紹API Level 11 之后的Notification實(shí)例獲取方法。

1. MIN API Level < 16 構(gòu)建Notification實(shí)例的方法

1) 創(chuàng)建Notification.Builder實(shí)例

      Notification.Builder builder = new Notification.Builder(context) 
      .setAutoCancel(true) //設(shè)置點(diǎn)擊通知后自動(dòng)取消通知
      .setContentTitle("title") //通知標(biāo)題
      .setContentText("describe") //通知第二行的內(nèi)容
      .setContentIntent(pendingIntent) //點(diǎn)擊通知后,發(fā)送指定的PendingIntent
      .setSmallIcon(R.drawable.ic_launcher); //通知圖標(biāo),必須設(shè)置否則通知不顯示

2) 調(diào)用Notification.Builder的getNotification()方法獲得Notification 

                     notification = builder.getNotification();

2. MIN API Level >=16 構(gòu)建Notification實(shí)例的方法

            Notification notification = new Notification.Builder(context)
            .setAutoCancel(true)
            .setContentTitle("title")
            .setContentText("text")
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentIntent(pendingIntent)
            .build();

三、發(fā)送通知

                          notificationManager.notify(1,notification);

以上就是對(duì)Android 通知欄的知識(shí)資料整理,后續(xù)繼續(xù)補(bǔ)充,謝謝大家對(duì)本站的支持。

相關(guān)文章

最新評(píng)論

灵台县| 博罗县| 渭源县| 启东市| 康定县| 绍兴县| 汉寿县| 蕲春县| 垫江县| 南宁市| 香河县| 富蕴县| 汽车| 卓尼县| 子洲县| 易门县| 宁城县| 车险| 井研县| 筠连县| 佳木斯市| 天柱县| 叙永县| 阜南县| 昌吉市| 临武县| 隆尧县| 德钦县| 金门县| 曲水县| 安庆市| 双江| 慈利县| 白河县| 巴中市| 古田县| 邯郸县| 邢台市| 金沙县| 古交市| 崇左市|