android添加常驻图标到状态栏
2014-04-24 14:11
375 查看
/ *
*
如果没有从状态栏中删除ICON,且继续调用addIconToStatusbar,则不会有任何变化.如果将notification中的resId设置不同的图标,则会显示不同的图标
*
/
private void
addIconToStatusbar(int resId){
NotificationManager nm = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
Notification n = new Notification();
//常驻状态栏的图标
n.icon = resId;
// 将此通知放到通知栏的"Ongoing"即"正在运行"组中
n.flags |=
Notification.FLAG_ONGOING_EVENT;
// 表明在点击了通知栏中的"清除通知"后,此通知不清除,
经常与FLAG_ONGOING_EVENT一起使用
n.flags |= Notification.FLAG_NO_CLEAR;
PendingIntent pi =
PendingIntent.getActivity(this, 0, getIntent(),
0);
n.contentIntent = pi;
n.setLatestEventInfo(this,
getString(R.string.flow), "10M/30M", pi);
nm.notify(NOTIFICATION_ID_ICON,
n);
}
private void deleteIconToStatusbar(){
NotificationManager nm = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(NOTIFICATION_ID_ICON);
}
*
如果没有从状态栏中删除ICON,且继续调用addIconToStatusbar,则不会有任何变化.如果将notification中的resId设置不同的图标,则会显示不同的图标
*
/
private void
addIconToStatusbar(int resId){
NotificationManager nm = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
Notification n = new Notification();
//常驻状态栏的图标
n.icon = resId;
// 将此通知放到通知栏的"Ongoing"即"正在运行"组中
n.flags |=
Notification.FLAG_ONGOING_EVENT;
// 表明在点击了通知栏中的"清除通知"后,此通知不清除,
经常与FLAG_ONGOING_EVENT一起使用
n.flags |= Notification.FLAG_NO_CLEAR;
PendingIntent pi =
PendingIntent.getActivity(this, 0, getIntent(),
0);
n.contentIntent = pi;
n.setLatestEventInfo(this,
getString(R.string.flow), "10M/30M", pi);
nm.notify(NOTIFICATION_ID_ICON,
n);
}
private void deleteIconToStatusbar(){
NotificationManager nm = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(NOTIFICATION_ID_ICON);
}
相关文章推荐
- android添加常驻图标到状态栏
- Android 添加常驻图标到状态栏
- android添加常驻图标到状态栏
- android添加常驻图标到状态栏
- android添加常驻图标到状态栏
- android 状态栏添加图标的函数
- android实现状态栏添加图标的函数实例
- android 状态栏添加图标
- Android SystemUI状态栏添加图标
- Android下添加状态栏图标的方法
- Android SystemUI状态栏添加图标
- Android 标题栏添加常驻图标 Notification
- Android 4.2 状态栏添加图标
- android 状态栏添加图标的函数
- 为android添加耳机状态图标
- android 添加快捷方式并且图标上添加数字
- android 源码 在状态栏添加 虚拟按键(back,home,menu)