Search code examples
androidbroadcastreceiver

Boot Receiver Not Working in Oreo


I've been reading answers for about an hour, but can't see what I'm doing wrong that is stopping my Boot Receiver from firing.

This is in my Manifest -

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

<receiver
            android:name=".BootReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter android:priority="500">
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

And my BootReceiver looks like this -

public class BootReceiver extends BroadcastReceiver {

    private static final String TAG = "BootReceiver";

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

        Log.i(TAG ,"onReceive");

        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            Log.i(TAG ,"onReceive2");
            new MainActivity().nextNotification(context);
        }
    }
}

As far as I can see, this should be all I need? What could I be missing?

I'm reasonably sure it was working previously (maybe on Android N) but it's not firing now (Android O).

Is there anything I could have missed? It doesn't work on the emulator, or on my Pixel. In fact, it works fine on the emulator on API 21. I thought Boot Receiver was white listed on Oreo?


Solution

  • Sometimes Android Studio can bug out. (v3.0 Beta 4 here) Close it all the way down and restart it and that worked for me.