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

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

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

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

金蝶K3 BOS单据 完整显示单据头

金蝶K3 BOS单据 完整显示单据头

进入到序时簿,格式->选项设置 以委外订单为例: 弹出选项设置窗口,不要勾选【合并同一张单据的表头项目】,最后点击【确定】按钮。...

Proteus7.10SP0安装&和谐包下载

dxswp 这位仁兄出手太快了,网上Proteus7.10安装包刚出来,ta就和谐了。NB人士。赞一个。 安装文件 http://115.com/file/be4tmeh4#  基于Nemo78  7.10 sp0 crack 修改。 中文系统可用,...

金蝶K3中用户组和用户的权限导入导出

金蝶K3中用户组和用户的权限导入导出

帐套管理-帐套-用户引入引出...

太阳能板发电原理

太阳表面温度高达摄氏6000度,内部不断进行核聚变反应,并且以辐射方式向宇宙空间发射出巨大能量。人类有三个途径利用太阳能:光热转换、光电转换及光化转换。 光热转换即靠集热器把太阳能收集,可应用于将水加热,或在寒带地区的冬季,设计太阳能暖房让人抵抗低温。太阳能暖房系统由太阳能收集器、热储存装置、...

SVN修改Log信息

SVN修改Log信息

SVN默认是不能修改Log的,强行修改会报错:Repository has not been enabled to accept revision propchanges,ask the administrator to create a pre-revprop-change hook 如果需要修改...

C# MDI子窗体启动后没有最大化

C# MDI子窗体启动后没有最大化

目的: 子窗口启动显示后最大化,也就是填充了整个父窗体 但是发现一个问题: 如果在 Visual Studio 2005里通过属性工具栏设定了子窗体的 WindowState 为 Maximized,然后在运行过程中会发现子窗体实例化时不会最大化,而是当改变了父窗体的大小之后才随即最大化。而通过在子...

发表评论

访客

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