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

首頁 > 系統 > Android > 正文

android實現狀態欄添加圖標的函數實例

2020-04-11 11:24:29
字體:
來源:轉載
供稿:網友

本文實例講述了android實現狀態欄添加圖標的函數。分享給大家供大家參考。具體如下:

private void showNotification() {  // 創建一個NotificationManager的引用  NotificationManager notificationManager = (NotificationManager)   AutoFile.this.getSystemService(android.content.Context.NOTIFICATION_SERVICE);  // 定義Notification的各種屬性  Notification notification = new Notification(R.drawable.dvd,   "天籟之音播放器", System.currentTimeMillis());  notification.flags |= Notification.FLAG_ONGOING_EVENT; // 將此通知放到通知欄的"Ongoing"即"正在運行"組中  notification.flags |= Notification.FLAG_NO_CLEAR; // 表明在點擊了通知欄中的"清除通知"后,此通知不清除,經常與FLAG_ONGOING_EVENT一起使用  notification.flags |= Notification.FLAG_SHOW_LIGHTS;  notification.defaults = Notification.DEFAULT_LIGHTS;  notification.ledARGB = Color.BLUE;  notification.ledOnMS = 5000;  // 設置通知的事件消息  CharSequence contentTitle = "天籟之音正在播放……"; // 通知欄標題  CharSequence contentText = "ameyume"; // 通知欄內容  Intent notificationIntent = new Intent(AutoFile.this, MyPlayerService.class); // 點擊該通知后要跳轉的Activity  PendingIntent contentItent = PendingIntent.getActivity(AutoFile.this, 0,   notificationIntent, 0);  notification.setLatestEventInfo(AutoFile.this, contentTitle, contentText,   contentItent);  // 把Notification傳遞給NotificationManager  notificationManager.notify(0, notification); } 

要刪除圖標,用以下代碼:

// 啟動后刪除之前我們定義的通知 NotificationManager notificationManager = (NotificationManager) this  .getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(0);

希望本文所述對大家的Android程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 呼玛县| 拜泉县| 岫岩| 思南县| 蓬莱市| 曲阜市| 东平县| 河北区| 桐城市| 犍为县| 合作市| 维西| 宜兴市| 建阳市| 邯郸市| 琼中| 新河县| 聂荣县| 惠安县| 剑河县| 寿宁县| 江孜县| 孙吴县| 腾冲县| 和顺县| 九江市| 安乡县| 库尔勒市| 云和县| 平原县| 开封县| 五莲县| 耿马| 贵阳市| 辰溪县| 苏州市| 肥西县| 宁津县| 西城区| 上饶市| 仪征市|