Search code examples
androidandroid-intentandroid-servicebootcompletedhuawei-mobile-services

Intent BOOT_COMPLETED not working on Huawei device


I want to listen to APN Changes in my Android App.

Therefore I start a Service on android.intent.action.BOOT_COMPLETED. This Service starts a ContentObserver which listens to changes to content://telephony/carriers/preferapn.

I tested this setup on a few different devices (e.g. LG Spirit with Android 5.0, Samsung A3 with 6.0, Emulator Nexus5 with 7.0 and Huawei P9 Lite with 7.0)

On the Huawei phone onCreate of my Service is not called.

My other approach with android.intent.action.ANY_DATA_STATE in combination with a BroadcastReceiver which is registerd in the Manifest doesn't work either on this phone.

relevant parts of my manifest:

<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>

Solution

  • Huawei Phones have a built-in startup manager, it could be that the app is not yet enabled.

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

    Go to Settings > All, and choose Startup manager. This program is used to manage startup apps on Android phone. Allow or disallow app to run automatically after the Huawei phone starts up.