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

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

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

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

一、獲取NotificationManager實例

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

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

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

1. MIN API Level < 16 構建Notification實例的方法

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

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

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

                     notification = builder.getNotification();

2. MIN API Level >=16 構建Notification實例的方法

            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);

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

相關文章

最新評論

东阿县| 临潭县| 万载县| 武强县| 古交市| 措美县| 潍坊市| 平邑县| 合作市| 满洲里市| 攀枝花市| 南靖县| 茶陵县| 绥棱县| 游戏| 抚州市| 达孜县| 三江| 石棉县| 新源县| 海兴县| 张掖市| 包头市| 西盟| 临湘市| 黔西县| 崇义县| 大安市| 镇坪县| 忻城县| 汉沽区| 襄城县| 浮山县| 夏邑县| 奉化市| 彭州市| 吴旗县| 乌恰县| 霍林郭勒市| 班戈县| 延庆县|