<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:andro
    package="com.example.broadcastofboot">
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver
            android:name=".BootCompleteReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>
    </application>

</manifest>

然而,开机并不能接受到广播。

后来在网上查看问题所在,找到答案。

如果是三方应用没有系统权限的话,无解。
原因如下:
谷歌为了安全考虑(避免流氓软件、病毒啊干坏事,还能提高效率),4.0以后加了2个Flag:FLAG_INCLUDE_STOPPED_PACKAGES和FLAG_EXCLUDE_STOPPED_PACKAGES。系统发出的广播带有FLAG_EXCLUDE_STOPPED_PACKAGES这个flag,在应用进程没有启动的情况下是不能接收到的。
当然如果是用户自定义的广播可以带有FLAG_INCLUDE_STOPPED_PACKAGES这个flag,那么即使应用没启动也可以收到广播(很遗憾啊!只能是三方自定义的广播)。

链接:http://bbs.csdn.net/topics/390630274/

相关文章:

  • 2021-11-25
  • 2021-12-07
  • 2022-12-23
  • 2018-12-14
  • 2022-01-31
  • 2021-09-09
  • 2021-12-15
猜你喜欢
  • 2021-11-18
  • 2022-12-23
  • 2022-02-24
  • 2022-12-23
  • 2021-10-16
  • 2022-12-23
  • 2021-07-10
相关资源
相似解决方案