How does android resolve multiple entries in the AndroidManifest for the same broadcast receiver with different permissions and intent-filters?
I have run into this issue of defining permissions that are specific to intent-filters for a particular broadcast receiver. I was wondering how Android would resolve something below, and if there is a better way to do this.
<receiver android:name=".MyReceiver"
android:permission="com.permission.XY"
android:exported="true">
<intent-filter>
<action android:name="com.local.intent.ACT" />
</intent-filter>
</receiver>
<receiver android:name=".MyReceiver"
android:permission="com.permission.Z"
android:exported="true">
<intent-filter>
<action android:name="com.local.intent.SLOW_ACT" />
开发者_运维技巧 </intent-filter>
</receiver>
I am interested in knowing whether if both the above receiver tags are included in AndroidManifest, how it will be resolved by Android, and whether it will allow me to achieve what I intend, which is to enforce permission XY for ACT intent, and Z for SLOW_ACT. Note that it is the same receiver object for both.
I'm really not sure how it would handle the two different ones, but regardless, I would say it's bad practice to use two manifest listings for one receiver. What you could do is just make two Broadcast receivers, or just make one receiver with both intent filters. Then you could use extra data to control whether it matches what you wanted or not.
Really, I would recommend two receivers, though.
And I would THINK that your one receiver would have both intent filters and both permissions would be required for every call. Really all you could do to find out is test it.
精彩评论