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

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

xjtudll8年前 (2017-11-25)技术心得2260

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实现状态栏添加图标的函数” 的相关文章

Altium导入网表Netlist

Altium导入网表Netlist

用Altium的时候,发现原来Protel99SE里面的通过Netlist更新到PCB的功能不见了。乍一看,似乎只能通过Update来更新PCB了,其实不然,原来通过Netlist更新PCB的功能依然存在,只是难以找到这个功能菜单而已。 在Altium里面,是show difference方式的,...

iOS10,Xcode8上传AppStore的时候,找不到构建版本

iOS10,Xcode8上传AppStore的时候,找不到构建版本

参考资料:http://blog.csdn.net/u013283787/article/details/52593143 使用Xcode8成功上传app之后,在itunes connect 构建版本里根本找不到上传的版本。 网上搜了搜,又查了一下邮件    &nb...

AutoCAD转Altium

以前写过一篇文章,讲述了AutoCAD如何转Protel99SE [AutoCAD转Protel99SE及丢线问题解决] 现在公司不允许用Protel99SE了(因版权问题),买了正版的Altium。因此,要将AutoCAD转Altium,其实是可以用上面的办法的,那个办法依旧有效。 还有一个...

Xcode Warning: The Copy Bundle Resources build phase contains this target's Info.plist file

Xcode Warning: The Copy Bundle Resources build phase contains this target's Info.plist file

问题: 编译时,提示The Copy Bundle Resources build phase contains this target's Info.plist file 原因: Info.plist被添加到了Copy Bundle Resources里,原因不明。如图所示: 解决...

Altium打印设置文件.OutJob修改

Altium打印设置文件.OutJob修改

对于打印设置来说,很多时候设置是几乎相同的,如果新建打印设置文件(通过【File】->【Smart PDF】),那么每次都要重复一些设置工作,相当的繁琐。我们可以通过拷贝之前别的project的.OutJob文件,来简化这些操作。需要注意的是,要对这个.OutJob文件进行修改,不然输出的文件...

Word通配符全攻略

Normal 0 7.8 磅 0 2 什么是WORD通配符?通配符是配合WORD查找、替换文档内容的有利武器。打开WORD,按Ctrl+F,点击&ldq...

发表评论

访客

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