Now as of Oreo, Android apps should remove all implicit broadcasts in the manifest file.
For my Music Player application, for earlier versions, I need to declare these actions in the manifest:
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
<action android:name="android.intent.action.HEADSET_PLUG" />
</intent-filter>
I don't know if android supports declaring a manifest file per api version like in resources or not.
So how to retain backwards compatibility as earlier versions require that this broadcasts to be declared in the manifest.
Thanks
Now as of Oreo, Android apps should remove all implicit broadcasts for the manifest file.
You are welcome to register for broadcasts in the manifest. You just will not receive those broadcasts on Android 8.0+.
I don't know if android supports declaring a manifest file per api version like in resources or not
Not really.
If for some reason you really do not want to have that <intent-filter>
in your manifest for Android 8.0+, I can think of two options:
Have separate product flavors for pre-Oreo and post-Oreo versions, and have the <intent-filter>
in the manifest for the source set tied to your pre-Oreo flavor.
Have two <receiver>
elements, pointing to different receiver classes, where one is just a simple subclass of the other. On one of the two <receiver>
elements, have your <intent-filter>
. Then, have a res/values/bools.xml
file that defines a boolean resource (e.g., listenToMusic
) as true
, and a res/values-v26/bools.xml
file that defines the same resource as false
. In the <receiver>
with the <intent-filter>
, have android:enabled="@bool/listenToMusic"
, so that particular receiver (and its <intent-filter>
) will be disabled on Android 8.0+.
But, neither of those are needed. Just leave your manifest alone, bearing in mind that you will not receive the desired broadcasts.