Intent BOOT_COMPLETED 不适用于华为设备

Intent BOOT_COMPLETED not working on Huawei device

我想在我的 Android 应用程序中收听 APN 更改。

因此我在 android.intent.action.BOOT_COMPLETED 上启动了一项服务。 该服务启动一个 ContentObserver,它监听对 content://telephony/carriers/preferapn.

我在几个不同的设备上测试了此设置(例如,Android 5.0 的 LG Spirit、6.0 的三星 A3、7.0 的模拟器 Nexus5 和 7.0 的华为 P9 Lite)

在华为phoneonCreate上我的Service没有被调用

我将 android.intent.action.ANY_DATA_STATE 与在清单中注册的 BroadcastReceiver 结合使用的其他方法在此 phone.

上也不起作用

我的清单的相关部分:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>  

...

<receiver android:name=".ConnectivityChangeReceiver">
    <intent-filter>
        <action android:name="android.intent.action.ANY_DATA_STATE" />
    </intent-filter>
</receiver>

<receiver android:name=".APNChangedServiceStarter" >
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.QUICKBOOT_POWERON" />
        <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
    </intent-filter>
</receiver>

<service android:name=".APNChangedService"></service>

华为手机内置了启动管理器,可能是该应用尚未启用。

前往“设置”>“全部”,然后选择“启动管理器”。 此程序用于管理 Android phone 上的启动应用程序。 允许或禁止应用程序在华为 phone 启动后自动 运行。

为了更新,华为更改了Android9版本的菜单路径。

Huawei Mate 10 pro 上这个菜单的访问方式:
设置 -> 电池 -> 应用启动 -> 禁用应用的自动管理。

将出现一个弹出窗口,询问您要允许什么(默认情况下均为 true)。确保第一个自动启动已启用