java手机状态栏圆形图标,android实现状态栏添加图标的函数实例
本文實(shí)例講述了android實(shí)現(xiàn)狀態(tài)欄添加圖標(biāo)的函數(shù)。分享給大家供大家參考。具體如下:
private void showNotification() {
// 創(chuàng)建一個(gè)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"即"正在運(yùn)行"組中
notification.flags |= Notification.FLAG_NO_CLEAR; // 表明在點(diǎn)擊了通知欄中的"清除通知"后,此通知不清除,經(jīng)常與FLAG_ONGOING_EVENT一起使用
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.defaults = Notification.DEFAULT_LIGHTS;
notification.ledARGB = Color.BLUE;
notification.ledOnMS = 5000;
// 設(shè)置通知的事件消息
CharSequence contentTitle = "天籟之音正在播放……"; // 通知欄標(biāo)題
CharSequence contentText = "ameyume"; // 通知欄內(nèi)容
Intent notificationIntent = new Intent(AutoFile.this, MyPlayerService.class); // 點(diǎn)擊該通知后要跳轉(zhuǎn)的Activity
PendingIntent contentItent = PendingIntent.getActivity(AutoFile.this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(AutoFile.this, contentTitle, contentText,
contentItent);
// 把Notification傳遞給NotificationManager
notificationManager.notify(0, notification);
}
要?jiǎng)h除圖標(biāo),用以下代碼:
// 啟動(dòng)后刪除之前我們定義的通知
NotificationManager notificationManager = (NotificationManager) this
.getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel(0);
希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。
總結(jié)
以上是生活随笔為你收集整理的java手机状态栏圆形图标,android实现状态栏添加图标的函数实例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 小程序测试用例模板_微信小程序样式:高质
- 下一篇: Tomcat提示“XDB 的服务器 lo