Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registering BOOT_COMPLETED receiver in Android 8

We are about to update our App Android API 26. In the documentation about Broadcast receiver it says that

Apps that target Android 8.0 or higher can no longer register broadcast receivers for implicit broadcasts in their manifest

Implicit broadcast receivers are described as

a broadcast that does not target that app specifically. For example, ACTION_PACKAGE_REPLACED

So I assume that android.intent.action.BOOT_COMPLETED is considered an implicit receiver.

Further it states that implicit receivers must be registered within an Activity by using Context.registerReceiver(). But that wouldn't make sense for a receiver, which is listening for the BOOT_COMPLETED event.

What is the proper way to handle this? Can i keep this receiver in my manifest?

like image 263
4ndro1d Avatar asked Aug 31 '17 12:08

4ndro1d


People also ask

Where do I register and unregister broadcast receiver?

Receiver can be registered via the Android manifest file. You can also register and unregister a receiver at runtime via the Context. registerReceiver() and Context. unregisterReceiver() methods.

How do you check if a receiver is registered Android?

You can put a flag into your class or activity. Put a boolean variable into your class and look at this flag to know if you have the Receiver registered. Create a class that extends the Receiver and there you can use: Singleton pattern for only have one instance of this class in your project.

On which thread broadcast receivers will work in Android?

Broadcast Receiver by default runs on Main Thread only.

Which are the broadcast receiver are available in Android?

There are mainly two types of Broadcast Receivers: Static Broadcast Receivers: These types of Receivers are declared in the manifest file and works even if the app is closed. Dynamic Broadcast Receivers: These types of receivers work only if the app is active or minimized.


2 Answers

BOOT_COMPLETED is still accepted.

https://developer.android.com/guide/components/broadcast-exceptions.html

No need to change anything. Make sure you test in Android 8.

like image 186
Frank Avatar answered Nov 15 '22 22:11

Frank


ACTION_BOOT_COMPLETED is on the implicit broadcast whitelist, and so you can register for it in the manifest.

like image 35
CommonsWare Avatar answered Nov 15 '22 21:11

CommonsWare