国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

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

2019-12-12 05:42:33
字體:
來源:轉載
供稿:網友

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

一、獲取NotificationManager實例

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

二、創建Notification實例

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

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

1) 創建Notification.Builder實例

      Notification.Builder builder = new Notification.Builder(context)       .setAutoCancel(true) //設置點擊通知后自動取消通知      .setContentTitle("title") //通知標題      .setContentText("describe") //通知第二行的內容      .setContentIntent(pendingIntent) //點擊通知后,發送指定的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();

三、發送通知

                          notificationManager.notify(1,notification);

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 岱山县| 榆林市| 磴口县| 宁远县| 潍坊市| 军事| 宜昌市| 水城县| 长子县| 霍山县| 永康市| 丰宁| 望谟县| 右玉县| 三亚市| 长兴县| 麦盖提县| 靖远县| 安西县| 长阳| 扎鲁特旗| 新邵县| 怀化市| 驻马店市| 扶绥县| 红原县| 桑植县| 嘉定区| 本溪市| 大丰市| 鹿泉市| 荃湾区| 洛南县| 桂平市| 宝应县| 景德镇市| 老河口市| 什邡市| 望江县| 班戈县| 吉林市|