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

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

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

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

C# textBox框实现输入下拉列表

C# textBox框实现输入下拉列表

textBox框像百度搜索出现下拉列表的样式,如图: 重点就是要关注:AutoCompleteMode和AutoCompleteSource两种属性。 具体实现代码如下: 将此方法在frmLogin_Load事件里加载, private void bindTxt() {   ...

C#实现重启应用程序

推荐使用: Application.Restart();...

Quartus Error: Signal "XX" drives an input pin”

问题: Quartus II编译提示:“Error: Signal "B" drives an input pin” 原因: 不该相连的节点(或PIN)连接到了一起了,有可能是被自动连接上了,删除不需要的连接即可。 还有种情况是:导线的名称跟Input...

Xcode:failed to get the task for process XXX 解决办法

问题:     iOS真机调试程序,报如下错误信息:failed to get the task for process XXX 原因: 证书问题,project和target的证书都必须是开发证书,不能用分发证书。 解决方案:     p...

IIS配置允许下载APK文件

IIS配置允许下载APK文件

MIME类型:application/vnd.android.package-archive...

CTE递归限制次数

CTE递归限制次数

https://blog.csdn.net/weixin_30247159/article/details/98657005 CTE可以用来取递归,网上资料很多,这里就不再叙述了,今天遇到的需求是要限制只取2级,然后加了个临时的lev with tree as ( select [Cu...

发表评论

访客

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