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