6

I have created an Android application that should start a service after BOOT. It works just fine on a Nexus 5 phone, but I can not make it work on a Huawei tablet (Mediapad X2). I am using Android 5.0 / API 21.

The manifest has the proper permissions/intents according to the guidelines.

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

    <receiver
        android:name=".BootBroadcast"
        android:enabled="true"
        android:exported="true"
        android:label="BootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
        </intent-filter>
    </receiver>

I search SO for similar issues (BOOT_COMPLETED not working Android) and have added the QUICKBOOT_POWERON intent, as well as the WAKE_LOCK permission but nothing has changed.

The Broadcast Receiver is just starting the service

public class BootBroadcast extends BroadcastReceiver {

private static final String TAG = "GrandUnion-Boot";

@Override
public void onReceive(Context context, Intent intent) {

    Log.e(TAG, "Boot_Completed RECEIVED");
    try{
        context.startService(new Intent(context,MyService.class));
        Log.i(TAG, "Boot Completed - start service");
    }catch(Exception e){
        Log.e(TAG,e.toString());
    }

}
}
Community
  • 1
  • 1
Konstantinos
  • 556
  • 4
  • 9
  • Possible duplicate with http://stackoverflow.com/questions/24882861/android-intent-action-boot-completed-intent-is-not-received-at-restart-or-reb – KostasC Jan 18 '16 at 13:28
  • I don´t think it´s a duplicate because OP said that he also added Quickboot..... – Opiatefuchs Jan 18 '16 at 13:31
  • 1
    Have you tried adding `` to the `intent-filter`? – Knossos Jan 18 '16 at 13:31
  • Hi @KostasC, as I mentioned in my post, I searched SO and considered their replies (e.g. adding the QUICKBOOT_POWERON action) but with no result. Is there any other 'hidden' intent for Huawei devices? – Konstantinos Jan 18 '16 at 13:32
  • ...and some devices have some strange behaviour with the declaration in manifest. For example your receiver: android:name=".BootBroadcast". Sometimes it just helps if You write instead: "com.yourpackage.BootBroadcast" , I mean the full name. After that, clean up project, deinstall from device and install again. – Opiatefuchs Jan 18 '16 at 13:33
  • I added the category and package details as @Opiatefuchs suggested but nothing. – Konstantinos Jan 18 '16 at 13:55
  • where are your permissions declared? Outside the application-tag? – Opiatefuchs Jan 18 '16 at 14:01
  • Yes, they are outside for the whole package. – Konstantinos Jan 18 '16 at 14:13
  • As I said, the strange thing is that it works for the Nexus phone, but not for the Huawei tab. – Konstantinos Jan 18 '16 at 14:16

2 Answers2

4

After long researches I find out, that some devices have their own startup manager. And Huawei Mediapad one of those, so:

  1. Go to the settings of device
  2. Find startup manager
  3. Allow app to start.
  • Hi, thank you for this information, but the device does not have a startup manager. I have a "phone manager" but it does not have an option for boot/startup. – Konstantinos Apr 01 '16 at 11:16
  • @Konstantinos My test device is Huawei MediaPad X1. Problem was exactly the same. So your settings can differ. Is there any options provided, when your install app directly through apk? MediaPad1 displays option to allow automatically start on boot in that case. – Дмитрий Басарыгин Apr 13 '16 at 09:42
  • I have 10 huawei mediapad 2. 7 out of 10 works. but the other 3 does not. How can that be ? – Mr T Nov 03 '16 at 04:57
1

In case your device does not have a startup/boot manager, try checking the app manager. On Lenovo's VibeUI, the app manager has an option "restrict launch",which when enabled prevents the app from receiving BOOT_COMPLETED intent.

ranjan_purbey
  • 421
  • 4
  • 11