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

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

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

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://www.xjtudll.cn/Exp/480/

分享给朋友:

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

世界城市时间及时区

时区是地球上的区域使用同一个时间定义。以前,人们通过观察太阳的位置(时角)决定时间,这就使得不同经度的地方的时间有所不同(地方时)。时区通过设立一个区域的标准时间部分地解决了这个问题。世界各个国家位于地球不同位置上,因此不同国家的日出、日落时间必定有所偏差。这些偏差就是所谓的时差。 1884年国际经...

Android error:Duplicate ID, tag null, or parent id with another fragment(fragment嵌套问题)

参考资料:http://stackoverflow.com/questions/14083950/duplicate-id-tag-null-or-parent-id-with-another-fragment-for-com-google-androi 跟参考资料里的这个人一样,我也碰到了这个...

Quartus II Warning: Found 6 node(s) in clock paths which may be acting as ripple and/or gated clocks

Quartus II编译某代码之后,老是提示如下warning: Warning: Found 6 node(s) in clock paths which may be acting as ripple and/or gated clocks -- node(s) analyzed as buf...

利用Multisim设计数字滤波器

利用Multisim设计数字滤波器

【工具】->【Circuit Wizards】->【Filter Wizard】  可以设计低通,高通,带通,带阻,滤波器可以选是无源还是有源。不过这玩意儿还是没专业的滤波器设计软件好用。...

c# textbox的passwordchar清空

//三种都是清空 this.textBox1.PasswordChar = new char(); this.textBox1.PasswordChar = '\0'; this.textBox1.PasswordChar = default(char);...

Xcode5 Version与Build设置

Xcode5 Version与Build设置

在ios中,有两种version,一种是 CFBundleVersion ("Bundle Version"),也就是我们看到的Version,另一种是CFBundleShortVersionString ("Bundle version string, short&q...

发表评论

访客

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