java Android:OnBootReceiver:导出的接收器不需要许可

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13517128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 13:03:54  来源:igfitidea点击:

Android: OnBootReceiver: Exported receiver does not require permission

javaandroidbroadcastreceiverandroid-manifestbootcompleted

提问by Xander

I've created a BroadcastReceiver, which receives BOOT_COMPLETED.

我创建了一个BroadcastReceiver,它接收BOOT_COMPLETED.

In my AndroidManifest.xmlI've added it like so:

在我的AndroidManifest.xml我已经添加它像这样:

<receiver
    android:name=".OnBootReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" /> 
        <action android:name="android.intent.action.QUICKBOOT_POWERON" />
    </intent-filter>
</receiver>

However, I get the warning: Exported receiver does not require permission.I've read about it on SO, but I don't fully understand it.

但是,我收到警告:导出的接收器不需要许可。我已经在 SO 上阅读过它,但我并不完全理解它。

So could someone explain to this beginner :) why I'm getting this warning, and what to do against it (and why)?

所以有人可以向这个初学者解释 :) 为什么我收到这个警告,以及如何处理它(以及为什么)?

回答by AGK

The warning

警告

Exported receiver does not require permission

导出的接收器不需要许可

means, You have an intent-filter with some action (which means by default you have android:exported="true"set and it can now receive broadcasts from ANYbroadcasters outside of your application) Since it can receive broadcasts from ANYbroadcasters outside of your application, it warns you by saying "Hey, are you sure ANYbroadcaster can invoke you? In my opinion, it is better if you allow only those broadcasters to invoke you that has the permission you have set for this receiver through android:permission"

意味着,您有一个带有某些操作的意图过滤器(这意味着默认情况下您已经android:exported="true"设置并且它现在可以从您的应用程序之外的任何广播公司接收广播)由于它可以从您的应用程序之外的任何广播公司接收广播,它会通过以下方式警告您说“嘿,你确定任何广播公司都可以调用你吗?在我看来,如果你只允许那些广播公司通过android:permission为这个接收器设置权限来调用你会更好”

Hope this is clear!!!

希望这很清楚!!!

回答by spes

You can remove this warning by adding android:exported="false"to the receiver tag (see this answer: https://stackoverflow.com/a/11526028/757073)

您可以通过添加android:exported="false"到接收器标签来删除此警告(请参阅此答案:https: //stackoverflow.com/a/11526028/757073