Android的 - "出口接收器不需要任何许可"在接收器意味着从系统服务接收 [英] android - "Exported receiver does not require permission" on receivers meant to receive from system services

查看:144
本文介绍了Android的 - "出口接收器不需要任何许可"在接收器意味着从系统服务接收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在清单中声明一些接收器:

 <接收器LT;! - 没有警告 - >
    机器人:名称=。receivers.TriggerMonitoringBootReceiver
    机器人:启用=假>
    <意向滤光器>
        <作用机器人:名称=android.intent.action.BOOT_COMPLETED/>
    &所述; /意图滤光器>
< /接收器>
<接收器LT;! - 没有警告 - >
    机器人:名称=。receivers.ScanResultsReceiver
    机器人:启用=假>
    <意向滤光器>
        <作用机器人:名称=android.net.wifi.SCAN_RESULTS/>
    &所述; /意图滤光器>
< /接收器>
<接收器LT;  - 警告:导出的接收器不需要任何权限 - >
    机器人:名称=。receivers.BatteryMonitoringReceiver
    机器人:启用=假>
    <意向滤光器>
        <作用机器人:名称=@字符串/ intent_action_setup_alarm/>
        <作用机器人:名称=@字符串/ intent_action_cancel_alarm/>
        <作用机器人:名称=@字符串/ intent_action_monitor/>
    &所述; /意图滤光器>
< /接收器>
 

第一种是为了获得 BOOT_COMPLETED 的行动。二是为了获得 android.net.wifi.SCAN_RESULTS 。第三个是为了得到一些动作我播(intent_action_monitor)以及由 AlarmManager (intent_action_setup_alarm等)播放一些行动。
两个问题:

  • 为什么我没有拿到所有的接收器的警告?
  • 在什么权限需要设置的的接收器意味着从系统服务得到纠正警告的(我的理解它是什么,我不希望任何人使用反正我接收器)? 请问 输出=假 执行作为启动接收器,无线接收器,报警接收等的?
    我想用一个自定义权限与的android:的ProtectionLevel =signatureOrSystem但该文档建议不要这两者的保护级别自定义权限的。所以,我应该怎么处理这样的警告?

链接的文档和/或一些code将大大AP preciated。

解决方案
  

为什么我不能得到警告所有接收者?

由于前两个显然旨在通过Android的广播。最后一个是未知的,部分原因是因为您没有提供字符串资源值,可能是因为他们自己的独特操作字符串。

  

我需要什么权限,为接收器设置意味着从系统服务得到纠正警告

正确的解决方法是删除<意向滤光器> 。如果您在播放这些意图,或者如果你是包裹一个意图 getBroadcast( ) PendingIntent ,你不需要操作字符串。使用意图构造函数的Java类对象作为第二个参数,并使用:

 新意图(这一点,BatteryMonitoringReceiver.class)
 

欢迎您还在附加的操作字符串到意图,如果你想要的,但你可以转储<意向滤光器> (路由将基于所提供组件上,在这种情况下,Java类)

仅使用一个<意向滤光器> 时,你期望的操作系统或第三方应用程序来启动意图自己(执行 PendingIntent 您创建不计)。

I have some receivers declared in my manifest :

<receiver <!-- no warning -->
    android:name=".receivers.TriggerMonitoringBootReceiver"
    android:enabled="false" >
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>
<receiver <!-- no warning -->
    android:name=".receivers.ScanResultsReceiver"
    android:enabled="false" >
    <intent-filter>
        <action android:name="android.net.wifi.SCAN_RESULTS" />
    </intent-filter>
</receiver>
<receiver <!-- warning : Exported receiver does not require permission-->
    android:name=".receivers.BatteryMonitoringReceiver"
    android:enabled="false" >
    <intent-filter>
        <action android:name="@string/intent_action_setup_alarm" />
        <action android:name="@string/intent_action_cancel_alarm" />
        <action android:name="@string/intent_action_monitor" />
    </intent-filter>
</receiver>

The first one is meant to receive a BOOT_COMPLETED action. The second is meant to receive android.net.wifi.SCAN_RESULTS. The third one is meant to receive some actions I broadcast (intent_action_monitor) and some actions broadcasted by the AlarmManager (intent_action_setup_alarm etc).
Two questions :

  • Why don't I get the warning on all receivers ?
  • What permissions do I need to set for receivers meant to receive from system services to correct the warning (I understand what it is about and I don't want anyone to use my receivers anyway) ? Will exported="false" do for boot receivers, wifi receivers, alarm receivers etc ?
    I thought of using a custom permission with android:protectionLevel="signatureOrSystem" but the docs advise against both this protection level and custom permissions. So how I should handle this warning ?

Links to the docs and/or some code will be much appreciated.

解决方案

Why don't I get the warning on all receivers ?

Because the first two are clearly designed to be broadcast by Android. The last one is unknown, partly because you did not supply the string resource values, and possibly because they are your own unique action strings.

What permissions do I need to set for receivers meant to receive from system services to correct the warning

The correct solution is to delete the <intent-filter>. If you are broadcasting these Intents, or if you are wrapping an Intent in a getBroadcast() PendingIntent, you do not need action strings. Use the Intent constructor that takes the Java class object as the second parameter, and use that:

new Intent(this, BatteryMonitoringReceiver.class)

You are welcome to still attach an action string to that Intent, if you want, but you can dump the <intent-filter> (routing will be based on the supplied component, in this case the Java class).

Only use an <intent-filter> when you are expecting the OS or third-party apps to initiate the Intent themselves (executing a PendingIntent that you created does not count).

这篇关于Android的 - &QUOT;出口接收器不需要任何许可&QUOT;在接收器意味着从系统服务接收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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