本文介绍了Android:导出的接收者属性的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   <receiver
        android:name="MyReceiver"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
  </receiver>

我不明白是否需要通知.如果这是真的,任何应用程序都可以通过这些操作调用我的接收器?因此,如果我将其设为 false,系统可以将操作发送给我的接收器?

I don't understand if it's needed to be notified.If it were true any app could call my receiver with those actions? So If I make it false the system can send the actions to my receiver?

推荐答案

实际上,其他应用程序无法呼叫您的接收器".其他应用程序可以只发送广播 Intents.然后系统将呼叫所有注册的接收者.

Actually, others apps cannot "call your receiver". Other apps can just send broadcast Intents. The System will then call all registered receivers.

一般来说,您不必担心这一点.大多数这些广播 Intent 都受到保护,因此只有系统应用程序才能广播它们.例如,另一个应用程序尝试广播 BOOT_COMPLETED 将被忽略.如果您的 BroadcastReceiver 被流氓应用程序触发,因为它广播 CONNECTIVITY_CHANGE 会发生什么?可能什么都没有,因为您的应用无论如何都应该检查 onReceive() 中的真实连接状态,如果没有任何变化,您可以忽略它.

In general you shouldn't worry about this. Most of these broadcast Intents are protected so that only system apps can broadcast them anyway. An attempt by another app to broadcast BOOT_COMPLETED, for example, would just be ignored. What would happen if your BroadcastReceiver gets triggered by a rogue app because it broadcast CONNECTIVITY_CHANGE? Probably nothing, because your app should check the real connectivity state in onReceive() anyway, and if there isn't any change you can just ignore it.

此外,您不需要指定 android:enabled="true" 因为这是默认状态.你也不需要指定 android:exported="true" 因为你有一个 附加到你的 自动将 android:exported 设置为 true.

Also, you don't need to specify android:enabled="true" because this is the default state. You also don't need to specify android:exported="true" because you have an <intent-filter> attached to your <receiver> which automatically sets android:exported to true.

这篇关于Android:导出的接收者属性的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 14:25
查看更多