如何解决Android的多个条目在AndroidManifest具有不同的权限和意图过滤器相同的广播接收器? [英] How does android resolve multiple entries in the AndroidManifest for the same broadcast receiver with different permissions and intent-filters?

查看:450
本文介绍了如何解决Android的多个条目在AndroidManifest具有不同的权限和意图过滤器相同的广播接收器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已碰上限定特定于意图滤波器用于特定广播接收机权限的这个问题。我想知道的Andr​​oid将如何解决下面的东西,如果有更好的方法来做到这一点。

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>

我想知道是否如上述两种接收器标签都包含在AndroidManifest,怎么会被Android的解决,以及是否可以让我实现我打算,这是强制执行的权限XY ACT的意图,和Z为SLOW_ACT。需要注意的是两个相同的接收器对象

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.

这篇关于如何解决Android的多个条目在AndroidManifest具有不同的权限和意图过滤器相同的广播接收器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆