Differentiate an implicit broadcast receiver against an explicit broadcast receiver in a manifest

According to the Android O migration guide provided by Google, most of the implicit translation of an intent should not be recorded in the manifest (minus a few exceptions here ), but the explicit intent of the translation remains untouched.

We are going to transfer any necessary transfer from the manifest. But how do we know if a receiver is implied? Is there a general rule?

Here is an example of the translations that we register in the manifest. Should we only look at the action tag and see if it has a white list to keep it in the manifest?

<receiver android:name=".receiver.ImageBroadcastReceiver" android:enabled="true" > <intent-filter> <action android:name="android.hardware.action.NEW_PICTURE" /> <category android:name="android.intent.category.OPENABLE" /> <data android:mimeType="image/*" /> </intent-filter> </receiver> <receiver android:name=".receiver.InstallReferrerReceiver" android:exported="true"> <intent-filter> <action android:name="com.android.vending.INSTALL_REFERRER" /> </intent-filter> </receiver> <receiver android:name=".receiver.JoinEventReceiver" > <intent-filter> <action android:name="JOIN_ACTION" /> <action android:name="CANCEL_ACTION" /> <action android:name="DECLINE_ACTION" /> </intent-filter> </receiver> 

For example, the intent "com.android.vending.INSTALL_REFERRER" is not white. Should we register it in Activity? If it werenโ€™t, it was never fired, as during registration, the application is already installed? This is what confuses me when trying to figure out if the broadcast receiver is implicit or explicit, as I thought I only needed to check this action tag.

+7
android android-intent android-manifest android-broadcast android-8.0-oreo
source share
1 answer

But how do you know if a receiver is implicit?

If the Intent has a ComponentName , the Intent is explicit. Otherwise, it is implicit.

That ComponentName can be obtained in one of several ways, including:

  • It can be directly placed into an Intent (e.g. new Intent(this, TheReallyAwesomeReceiver.class )

  • With PackageManager and queryIntentReceivers() it can be directly placed in Intent to find the correct one, based on valid strings, etc.

  • It can be obtained by the system from the action line, etc. plus package defined via setPackage()

If we look only at the action tag and see if it is in the white list to save it in the manifest?

Not. You also need to think about the nature of the broadcast: does it go to any registered recipient or only to a specific application?

For example, the intent "com.android.vending.INSTALL_REFERRER" is not white. Should we register it with Activity?

Not. This transfer will only be available for a newly installed application, so it must be an explicit Intent . An action line, etc., to help the system determine which of the recipients you have registered is relevant.

Contrast this with ACTION_PACKAGE_ADDED . This is transmitted to any registered recipient; it will not be just one specific application. Therefore, the Intent must be implicit (otherwise it would have a ComponentName defining a specific receiver in a particular application). And, since ACTION_PACKAGE_ADDED not included in the white list, it is assumed that you cannot register for this broadcast in the manifest on Android 8.0 +.

+12
source share

All Articles