0

I've setup a broadcast receiver to start the service on BOOT_COMPLETED intent.

receiver is registered in manifest

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

RECEIVE_BOOT_COMPLETED permission is also given in manifest.

My app was running in background

package com.rebootandroid.reboot;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.util.Log;

import java.util.Set;

public class Receiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.i("Booted", "true");
        Log.i("action", action);

        NotificationCompat.Builder b = new NotificationCompat.Builder(context.getApplicationContext(), "defautl")
                .setAutoCancel(true)
                .setSmallIcon(R.mipmap.ic_launcher_round)
                .setContentTitle("Boot Intent Received")
                .setContentText("App starting....");
        NotificationManagerCompat nmc = NotificationManagerCompat.from(context.getApplicationContext());
        nmc.notify(111111111, b.build());

        Intent inTent = new Intent(context.getApplicationContext(), RebootService.class);
        inTent.putExtra(RebootService.INTENT_EXTRA, "RECEIVER_CLASS");
        context.getApplicationContext().startService(inTent);
    }
}

but when I reboot the device, I see in the logcat that android.intent.action.BOOT_COMPLETED is fired with the flag FLAG_EXCLUDE_STOPPED_PACKAGES... which is causing my app to not receive the boot completed intent...

I am using OPPO A71 using android 7.1 and redmi 4a using android 6.0.1

Disclaimer: the same code works perfect on emulator. in emulator the BOOT_COMPLETED intent is not fired with any of the flags...

  • The correct `` for the boot broadcast is `"android.intent.action.BOOT_COMPLETED"`, not `"android.intent.action.SIM_STATE_CHANGED"`. – Mike M. Aug 29 '19 at 14:37
  • actually I tried both of the intents just to figure it out if it is working or not... but both time if the intent is not fired with flags, it works, but if fired with FLAG_EXCLUDE_STOPPED_PACKAGES, it does not work... – Muhammad Ali Aug 29 '19 at 14:40
  • Yeah, that's the expected behavior. Why is your app stopped? Did you forcibly stop it manually? Have you just never launched it prior to rebooting? – Mike M. Aug 29 '19 at 14:43
  • my app was open when I rebooted my phone. I was on the launcher activity of my app when I rebooted the phone using the command `adb reboot` – Muhammad Ali Aug 29 '19 at 14:55
  • OK, those particular manufacturers possibly have some extra setting somewhere that disallows apps from starting at boot, or running in the background, by default. Try looking through the device Settings, and maybe any other standalone security-related apps for some such setting. I'll see if I can find some relevant information. – Mike M. Aug 29 '19 at 14:58
  • Have a look at these, to see if you've anything similar on your devices: https://stackoverflow.com/a/35770734, https://stackoverflow.com/a/38049557. – Mike M. Aug 29 '19 at 15:03
  • you are right Mike. There are some restrictions imposed by the manufacturers. I just want a way to bypass them. is it possible? – Muhammad Ali Aug 29 '19 at 16:23
  • Not likely. They're basically just like Android permissions, AFAIK, in that only the user can turn then on or off. Otherwise, they wouldn't really serve a purpose, right? Since every developer would just turn them off. – Mike M. Aug 29 '19 at 16:29

0 Answers0