当前位置:首页 > 技术心得 > 正文内容

android实现状态栏添加图标的函数

xjtudll9年前 (2017-11-25)技术心得7900

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

参考资料:http://www.jb51.net/article/73063.htm

扫描二维码推送至手机访问。

版权声明:本文由鸟的天空发布,如需转载请注明出处。

本文链接:http://xjtudll.cn/Exp/480/

分享给朋友:

“android实现状态栏添加图标的函数” 的相关文章

ios 获取应用程序的名称和版本号

.wiz-todo, .wiz-todo-img {width: 16px; height: 16px; cursor: default; padding: 0 10px 0 2px; vertical-align: -10%;-webkit-user-select: none;} .wiz-to...

Proteus7.8 SP2安装及破解包下载

老王这个人确实很牛啊,之前Proteus7.6和Proteus7.7都是他破解的,现在又将Proteus7.8 SP2破解了。   大概看了看,Proteus7.8新增的是几个PIC的单片机 Proteus7.8安装包下载地址: http://cache.ourdev.cn/bbs...

ios设备分辨率、屏幕尺寸、屏幕密度

iPhone Devices iPhone 5S Retina 4" Screen 326ppi 16:9 640 x 1136 px 123.8 x 58.6 x 7.6 mm 112...

位运算——交换两个数

交换两个数 交换两个数相信很多人天天写过,我也相信你每次都会使用一个额外来变量来辅助交换,例如,我们要交换 x 与 y 值,传统代码如下 int tmp = x; x = y; y = tmp; 这样写有问题吗?没问题,通俗易懂,万一哪天有人要为难你,**不允许...

Quartus II Warning:can't generate programming files because you are currently using the Quartus II softwore in Evaluation Node

开发环境: Quartus II 11.0 问题: 代码编译通过,但是下载到CPLD,没有任何现象 且有warning 如下: can't generate programming files because you are currently using the Quartus II softwo...

Qt无法定位程序输入点

Qt无法定位程序输入点

       Qt发布程序的时候,运行exe文件(位于release文件夹),提示Qt无法定位程序输入点于动态链接库QtCore4.dll上,如图所示。   碰到这个问题,当然第一件事是在\Qt\2009.05...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。