Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Broadcast Receiver on Android Oreo

I have a network change receiver class and it extends from broadcast Receiver, but I’m not pretty sure that it’s working in android Oreo, does Oreo support broadcast receiver, and if it doesn’t support, what’s the other way to do it

like image 223
Eder Padilla Avatar asked Jun 11 '18 13:06

Eder Padilla


1 Answers

Oreo supports Broadcast Receivers but with some restrictions on Implicit broadcast that are declared in manifest.

Implicit vs Explicit Broadcast:

According to the documentation, an implicit broadcast is a broadcast that does not target that app specifically. For example, ACTION_PACKAGE_REPLACED is an implicit broadcast, since it is sent to all registered listeners, letting them know that some package on the device was replaced.

However, ACTION_MY_PACKAGE_REPLACED is not an implicit broadcast, since it is sent only to the app whose package was replaced, no matter how many other apps have registered listeners for that broadcast.

So any broadcast receivers that we have defined statically within our application manifest that are listening for implicit broadcasts will no longer receive those broadcasts.

The reason for this change is that implicit broadcasts would previously trigger any component that was listening for them within the manifest— this could have an adverse effect on application and device performance due to large numbers of applications registered to receive specific broadcasts all being triggered at the same time.

But there is a list of exceptions when it comes to implicit broadcasts — this means that there are still some which you can register to receive broadcasts for. They are all listed below:

enter image description here

So if the broadcast that you have registered receivers for is on this list, then it will still function as it did previously. However, if the broadcast that you have registered to receive is not on this list then you should use some alternative solution like:

  • Create the receiver at runtime by calling Context.registerReceiver(), instead of declaring the receiver in the manifest.
  • Use a scheduled job to check for the condition that would have triggered the implicit broadcast.

For more information

like image 100
Rahul Sahni Avatar answered Oct 14 '22 12:10

Rahul Sahni