"出口活动并不需要许可"试图从URI启动时并不、启动时、QUOT、URI

2023-09-13 00:03:58 作者:趁早两清

我想推出从URI使用的是Android应用程序this SO质疑作为参考。

I am trying to launch an Android app from a URI using this SO question as a reference.

我有一个清单文件具有以下声明的活动:

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>

我在尝试推出MainActivity与 http://example.com 链接。我的问题是,我得到的警告

I am attempting to launch MainActivity with the http://example.com link. My issue is that I get the warning

"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.

我如何正确地写活动的意图过滤器,以避免该警告?

How do I write the activity intent-filter correctly to avoid the warning?

感谢

推荐答案

我有同样的问题,当我的更新的SDK到版本20 。我删除它加入机器人:出口属性格式:

I had the same issue when I updated SDK to version 20. I removed it adding android:exported propery:

<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:

机器人:出口:默认值取决于活动是否包含意图过滤器。不存在任何过滤器意味着活性可以通过指定其确切类名称仅调用。这意味着,该活动仅用于应用内部使用(因为其他人不知道类名称)。因此,在这种情况下,默认值是假。另一方面,的的至少一个过滤器的presence意味着该活动旨在供外部使用,所以默认值是真即可。

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".

由于导出接收器不需要任何权限的(至少皮棉信息是明确的),你说对了。

Since "Exported receiver does not require permission" (at least the LINT message is clear) ,you got it.