平台放开BOOT_COMPLETED广播接收

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(). 


猜你喜欢

转载自sunj.iteye.com/blog/2397534
今日推荐