Android 使用 Intent 过滤器导出规则

标签 android sonarqube android-manifest

我收到来自 sonarqube 的警告

Implement permissions on this exported component.

sonarqube warning


同时,Android 文档明确指出任何带有 <intent-filters> 的 Activity 应标记为 exported="true" .

https://developer.android.com/guide/topics/manifest/activity-element#exported

If an activity in your app includes intent filters, set this element to "true" to allow other apps to start it.

For example, if the activity is the main activity of the app and includes the category "android.intent.category.LAUNCHER".

If this element is set to "false" and an app tries to start the activity, the system throws an ActivityNotFoundException.

这是AndroidManifest.xml中警告的一些代码

<activity
    android:name=".example.WebViewActivity"
    android:exported="true"
    android:launchMode="singleTop">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        
        <data android:host="example.com" />
        <data android:scheme="http" />
        <data android:scheme="https" />
        <data android:pathPrefix="/app/Webview" />
    </intent-filter>
</activity>

那么,对于这个问题有什么建议吗?谢谢

最佳答案

如果您不想为组件实现任何权限,只需声明空字符串即可 - android:permission=""

关于Android 使用 Intent 过滤器导出规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73399278/

相关文章:

android - 如何为 snackbar android 中的操作设置 Onclicklistener?

java - SonarQube 问题 "Add at least one assertion to this test case"用于带有断言的单元测试?

java - 如何让Android上的Activity始终位于最前面?

android - 无法在我的设备中启动 Android 应用程序

java - Java:放入十进制数字时会崩溃[RESOLVE]

android - 在 Android 中动态地向资源字符串数组添加值

Android字符串编码和html实体转换

java - 空的 ObjectFactory 构造函数是 Sonar 中的关键问题

sonarqube - 如何通知 SonarQube 有关包重命名的信息?

android-manifest - 最大 sdk 版本和目标 sdk 版本有什么区别?