Intent BOOT_COMPLETED 不适用于华为设备

woo*_*dii 5 android android-intent android-service bootcompleted huawei-mobile-services

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

因此,我在android.intent.action.BOOT_COMPLETED. 此服务启动一个 ContentObserver,它侦听 content://telephony/carriers/preferapn.

我在几个不同的设备上测试了这个设置(例如 LG Spirit with Android 5.0、Samsung A3 with 6.0、Emulator Nexus5 with 7.0 和 Huawei P9 Lite with 7.0)

onCreate我的服务的华为手机上没有调用。

我的另一种方法与Manifest 中注册的android.intent.action.ANY_DATA_STATEa 相结合,BroadcastReceiver在这款手机上也不起作用。

我的清单的相关部分:

<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>
Run Code Online (Sandbox Code Playgroud)

Ark*_*ady 9

只是为了更新,华为在Android 9版本中更改了菜单路径。

在华为 Mate 10 pro 上,进入此菜单的方法是:
设置 -> 电池 -> 应用启动 -> 禁用应用的自动管理。

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


Den*_*nny 5

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

来自 https://www.isunshare.com/android/how-to-control-startup-apps-on-huawei-android.html

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

  • 在华为 Mate 10 pro 上,运行 Pie 执行以下操作:设置 -&gt; 电池 -&gt; 应用程序启动 -&gt; 禁用应用程序的自动管理 (5认同)