August 2, 2018 comments 89 Reads

In part 4 of the BroadcastReceiver tutorial, we will learn how to send and receive explicit broadcasts. These broadcast are not restricted by the Android Oreo implicit broadcast ban, because instead of just defining an action string, they specify the component they want to trigger directly.
There are different ways to send an explicit broadcast. We can send it to a BroadcastReceiver in our own app by using the intent constructor that takes a package context and the class name of the component, or by calling the setClass method on the intent. With setComponent and setClassName we can also send an explicit broadcast to a BroadcastReceiver in another app, in which case we have to set the receiver to exported=”true” in the manifest file. We can also only specify the package name with setPackage and provide an action string to let the system resolve this to an explicit component.
At the end we will learn about a workaround for the implicit broadcast ban, by using the PackageManager’s queryBroadcastReceivers method to find BroadcastReceivers with a particular action string to create and send explicit broadcasts to them, effectively executing an implicit broadcast that also works on Android Oreo.
Watch the whole playlist: