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

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

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

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

用宏定义代替printf函数

问题 有时候我们想用宏定义来决定是编译debug版本的代码还是release的代码,dubug版本的代码会通过printf打印调试信息,release版本的代码则不会。我们总不能对每一条printf都这样写: #if _DEBUG_printf("hello world!");...

K3 BOS 单据添加审核日期

K3 BOS 单据添加审核日期

https://blog.csdn.net/sz_bdqn/article/details/7291350   可能会出现如下问题:   多级审核流程界面的"业务审核日期"只有选项"不需要" 回到原单据,点击审核日期,将其属性锁定,全...

vs2010添加OLE/COM对象查看器

VS2010:工具——外部工具——"添加" 标题:OLE/COM对象查看器 命令:C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\OleView.Exe 点击&qu...

如何释放由RingtoneManage实例化的MediaPlayer

参考资料:http://stackoverflow.com/questions/15450255/how-to-release-the-mediaplayer-instantiated-by-ringtonemanager 为了获取android铃声的名称,使用了以下代码 //根据铃声地址获取铃声的...

SQL Server 树形递归查询

SQL Server 树形递归查询

原始查询 原始表格查询: select * from dbo.T_DeptInfo; 原始表格查询结果:: 递归查询 递归查询结果 带缩进的的树形递归查询 缩进递归查询结果 查询是否子节点的树形递归查询 树形递归查询是否包含子节点的查询结果...

SQL Server 2012 自动增长列,值跳跃问题(自增增加1000)【转载】

SQL Server 2012 自动增长列,值跳跃问题(自增增加1000)【转载】

介绍从 SQL Server 2012 版本开始, 当SQL Server 实例重启之后,表格的自动增长列的值会发生跳跃,而具体的跳跃值的大小是根据增长列的数据类型而定的。如果数据类型是 整型(int),那么跳跃值为 1000;如果数据类型为 长整型(bigint),那么跳跃值为 10000。从我们...

发表评论

访客

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