平台放开BOOT_COMPLETED广播接收

本文介绍Android 3.1之后系统对于开机自启动应用的限制,并提供了解决方案,包括如何确保应用能接收到BOOT_COMPLETED广播及调整广播接收优先级的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

android 3.1以后开机自启动受限制,没有手动启动过的程序,收不到开机广播
修改方法:
在AMS发BOOT_COMPLETED广播的地方加上intent.addFlags(Intent. FLAG_INCLUDE_STOPPED_PACKAGES 已经停止的应用也收能收到这个广播

注意事项:
1. 安装在sdcard的应用收不到广播,sdcard挂载晚
2. 系统开启了Fast Boot模式,系统启动并不会发送BOOT_COMPLETED广播
3. 自启动时间晚,可以调高广播接收的优先级
<intent-filter android:priority="1000">
// 可以提前开机自启动时间 -1000 ---- 1000
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>

android:priority
The priority that should be given to the parent component with regard to handling intents of the type described by the filter. This attribute has meaning for both activities and broadcast receivers:
It provides information about how able an activity is to respond to an intent that matches the filter, relative to other activities that could also respond to the intent. When an intent could be handled by multiple activities with different priorities, Android will consider only those with higher priority values as potential targets for the intent.
It controls the order in which broadcast receivers are executed to receive broadcast messages. Those with higher priority values are called before those with lower values. (The order applies only to synchronous messages; it's ignored for asynchronous messages.)
Use this attribute only if you really need to impose a specific order in which the broadcasts are received, or want to force Android to prefer one activity over others.

The value must be an integer, such as "100". Higher numbers have a higher priority. The default value is 0. The value must be greater than -1000 and less than 1000.

Also see setPriority().
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值