In the previous post I explained some changes you have to make if you want to call “startService()” in Android Oreo.

In this post, I will try to explain the set of changes you have to accomplish if you want to use BroadcastReceivers. But don’t forget to keep in mind all the Android parts affected when you target Android Oreo:

Services — Background limitations BroadcastReceivers Notifications RunTime Permissions Alarms Firebase Cloud Messaging (deadline April 2019)

BROADCAST RECEIVERS IN ANDROID OREO

Essentially, the problem in Android Oreo with BroadcastReceivers is that all BroadcastReceivers that we have declared in our AndroidManifest.xml and are listening to implicit intents will no longer receive those broadcasts (there are some cases that are allowed).

First of all, what is a implicit intent?

In Android we have two kind of intents to make an Action:

Implicit Intents: do not name a specific component, but instead declare a general action to perform. An example of implicit intent could be when we want to open an url, in this case we make something like this:

val browserIntent = Intent(Intent.ACTION_VIEW, URL);

startActivity(browserIntent);

Explicit Intents: specify which component is going to take the action and the user can’t do nothing. An example could be when we launch an Activity we make something like this:

val intent = Intent(context, ActivityB::class).

So if we have declared a BroadcastReceiver in our AndroidManifest.xml and is listening to implicit intents (that are no in the actions whitelist) will no receive the broadcast.

These are the implicit intent allowed:

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

So if we want to declare a broadcastReceiver and this is listening to a custom action we have to declare the class that will catch the action:

<!-- BROADCAST RECEIVER -->

<receiver android:name="your.package.BroadCastReceiver">

<intent-filter>

<action android:name="your.action" />

</intent-filter>

</receiver>

More info about BroadcastReceivers:

https://developer.android.com/guide/components/broadcasts