Android 尝试从 URI 启动时出现“导出的活动不需要许可”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11462936/
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
"Exported activity does not require permission" when attempting to launch from a URI
提问by Brad
I am trying to launch an Android app from a URI using this SO questionas a reference.
我正在尝试使用此 SO 问题作为参考从 URI 启动 Android 应用程序。
I have a manifest file with the following declared activity:
我有一个清单文件,其中包含以下声明的活动:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" android:host="example.com" />
</intent-filter>
</activity>
I am attempting to launch MainActivity with the http://example.comlink. My issue is that I get the warning
我正在尝试使用http://example.com链接启动 MainActivity 。我的问题是我收到警告
"exported activity does not require permission"
I have looked at other SO questions that report this same warning and all solutions don't seem to work.
我查看了其他报告相同警告的 SO 问题,所有解决方案似乎都不起作用。
How do I write the activity intent-filter correctly to avoid the warning?
如何正确编写活动意图过滤器以避免警告?
Thanks
谢谢
回答by Shine
I had the same issue when I updated SDK to version 20. I removed it adding android:exportedpropery:
当我将 SDK 更新到版本 20时,我遇到了同样的问题。我删除它添加android:exported属性:
<activity
android:name=".MainActivity"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" android:host="example.com" />
</intent-filter>
</activity>
inside the activity declaration in manifest. Of course you may specify this if the activity is intended only for application-internal use
在清单中的活动声明中。当然,如果活动仅供应用程序内部使用,您可以指定此项
The reason it fixes it is found on docs:
它修复它的原因可以在文档中找到:
android:exported:The default value depends on whether the activity contains intent filters. The absence of any filters means that the activity can be invoked only by specifying its exact class name. This implies that the activity is intended only for application-internal use (since others would not know the class name). So in this case, the default value is "false". On the other hand, the presence of at least one filter implies that the activity is intended for external use, so the default value is "true".
android:exported:默认值取决于活动是否包含意图过滤器。没有任何过滤器意味着只能通过指定其确切的类名来调用该活动。这意味着该活动仅供应用程序内部使用(因为其他人不知道类名)。所以在这种情况下,默认值为“false”。另一方面,至少存在一个过滤器意味着该活动是供外部使用的,因此默认值为 "true"。
Since "Exported receiver does not require permission"(at least the LINT message is clear) ,you got it.
由于“导出的接收器不需要许可”(至少 LINT 消息是明确的),您明白了。
回答by cleroo
Did you try to clean your project (Project > Clean ...) ? It fixed this warning for my project, maybe yours.
您是否尝试清理您的项目(项目 > 清理 ...)?它为我的项目修复了这个警告,也许是你的。
回答by white_gecko
To get rid of this warning you have two choices:
要消除此警告,您有两种选择:
- Either you set the attribute
android:exported="false"
on the Activity to prevent other Apps from calling your Activitythrough an intent - Or if allowing other Apps to call your Activityis what you want you need to add a
android:permission
attribute where you can specify which permissions an App needs to have in order to call your activity. - If you want to allow other Apps to call your Activity without any special permission it seam you have to get along with having a warning in the Manifest.
- 您可以
android:exported="false"
在 Activity 上设置属性以防止其他应用程序通过意图调用您的 Activity - 或者,如果您希望允许其他应用调用您的 Activity,则您需要添加一个
android:permission
属性,您可以在其中指定应用需要具有哪些权限才能调用您的 Activity。 - 如果您想允许其他应用程序在没有任何特殊许可的情况下调用您的活动,那么您必须在清单中显示警告。
You can get further information in the Android Documentation.
您可以在Android 文档 中获取更多信息。
Thanks to @furykidfor the links.
感谢@furykid提供的链接。