【问题标题】:Android exported rules with intent-filters带有意图过滤器的 Android 导出规则
【发布时间】:2022-11-10 09:37:10
【问题描述】:

我收到了来自 sonarqube 的警告说

对此导出的组件实施权限。


同时,android 文档明确指出任何带有<intent-filters> 的活动都应标记为exported="true"

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

如果您的应用程序中的活动包含意图过滤器,请将此元素设置为“true”以允许其他应用程序启动它。

例如,如果活动是应用程序的主要活动,并且包含类别“android.intent.category.LAUNCHER”。

如果此元素设置为“false”并且应用程序尝试启动 Activity,则系统会引发 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 sonarqube android-manifest


    【解决方案1】:

    对于这个问题,有两个解决方案,根据他们提到的在清单中添加导出的开发人员文档,

    Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present]
    

    但是在sonarqube 方面,如果我们在清单中添加这个标签,我们会在 DevOps 方面遇到问题,

    所以,解决方案是,

    1. SonarQube 方面应该将其更新为不是问题,因为 Android S+(>=31 版本)支持

    2. 您可以要求您的 DevOps 删除此问题以创建构建

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-14
      • 1970-01-01
      • 1970-01-01
      • 2012-02-22
      • 1970-01-01
      相关资源
      最近更新 更多