当前位置: 移动技术网 > IT编程>移动开发>Android > android实现状态栏添加图标的函数实例

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

淄博吧,飞库电子书,吕文斯基

本文实例讲述了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程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网