手机启动后,后台broadcast满天飞。可能点击自己应用的Notification 启动的broadcast半天不响应。这时候加上FLAG_RECEIVER_FOREGROUND吧。注意此flag在API 16中引入.
示例:
Intent intent = new Intent(context, XXXReceiver.class);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
}
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
...
注FLAG_RECEIVER_FOREGROUND的doc:
/**
* If set, when sending a broadcast the recipient is allowed to run at
* foreground priority, with a shorter timeout interval. During normal
* broadcasts the receivers are not automatically hoisted out of the
* background priority class.
*/
public static final int FLAG_RECEIVER_FOREGROUND = 0x10000000;
分享到:
相关推荐
Android Activity、Service、Broadcast、Notification四合一例子,Activity中点击按钮启动服务,服务里每4秒发送一次广播,广播接受者每接受到一个发送一条通知。
android service Notification BroadcastReceiver Intent 安装的服务开机自启动,service定时的打印消息,消息同时显示在通知栏,窗体界面的跳转,自定义控件的开发。系统广播,定时广播,轮询广播等。...
定时启动服务,通过服务创建一个通知,点击通知栏可以打开一个Activity。尽管关闭软件,通知栏也会出现通知。
博客《Uri详解之二——通过自定义Uri外部启动APP与Notification启动》对应源码,博客地址:http://blog.csdn.net/harvic880925/article/details/44781557
Bluetooth Alert Notification Profile
android服务自启动Service以及BroadcastReceiver和Notification.zip
主要利用了notification service 和receiver 实现了用户通知栏更新,失败了点击重新下载,下载好了点击自动安装,布局很丑,请根据自己项目的实际需求自行修改
Notification
这样一个通知就发送成功了,通知栏上也会显示出SmallIcon图标,之后是进行点击通知进行下载处理,首先Notification发送一个Broadcast广播,但是广播里面不能做耗时操作,所以在广播里开启一个Service服务,通过在...
Notification最新用法、实现Notification的通知栏常驻、Notification的各种样式big View、解决Notification点击无效
使用javascript 封装实现 Notification 消息通知框
各种Notification的使用技巧
示例功能包含普通Notification、折叠式Notification和悬挂式Notification,并且实现了Notification的显示等级。
android notification 通知 demo
调用getSystemService(NOTIFICATION_SERVICE)方法获取系统的NotifacationManager服务 通过构造器创建一个Notification对象 为Notification设置各种属性 通过NotificationManager发送Notification。
Android NOtification 使用Android NOtification 使用