You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android API 30包可见性<query>标签所需Intent类型及配置疑问

Android API 30 包可见性配置问题解答

疑问解答

  • 问题1:结论正确。是AndroidManifest.xml中标签的直接子元素,必须和标签平级,不能放在标签内部。
  • 问题2:你混淆了和组件的作用。的作用是声明你的应用需要查询系统中哪些其他应用的组件信息,和你自身应用的Activity配置完全无关,你自己Activity的不需要做任何移动,继续保留在Activity标签下即可,系统不会将中的规则和你自身的组件做绑定。
  • 问题3:不需要多次声明标签。全局只需要一个根标签,所有需要查询的Intent规则都作为子元素放在同一个标签内即可,即使有多个包含BROWSABLE的匹配规则,也只要按需添加多个子元素就行。
  • 问题4:该写法完全合规。标签内的标准子元素就是,用来声明你要查询的Intent匹配规则;而是用来声明自身组件可以响应的Intent规则,二者作用场景完全不同,开发者的写法是正确的。

修正后可运行完整代码

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.test">

    <!-- 包可见性声明,和application平级 -->
    <queries>
        <!-- 适配Usage1:查询ACTION_VIEW类型的Intent对应组件 -->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <!-- 若只需查询特定scheme的结果,可补充对应data声明 -->
            <data android:scheme="xxx" />
            <data android:scheme="https" />
        </intent>
        <!-- 适配Usage2:查询ACTION_SEND类型text/plain格式的Intent对应组件 -->
        <intent>
            <action android:name="android.intent.action.SEND" />
            <data android:mimeType="text/plain" />
        </intent>
    </queries>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Test">

        <activity
            android:name=".TestActivity"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan"
            android:exported="true">
            <!-- 修复原代码中文引号问题 -->
            <intent-filter>
                <data
                    android:host="open"
                    android:scheme="xxx" />

                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>

            <intent-filter
                android:autoVerify="true"
                tools:targetApi="m">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="www.xxx.com"
                    android:pathPrefix="/"
                    android:scheme="https" />

            </intent-filter>
        </activity>

        <activity
            android:name=".ABCActivity"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustResize"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="image/*" />
            </intent-filter>
        </activity>

    </application>

</manifest>

额外说明

  • Usage3获取自身应用版本名的逻辑不需要额外声明规则,应用自身的包信息默认可见。
  • 补充了Activity的android:exported属性,API 31及以上要求所有包含的组件必须显式声明exported属性,避免编译报错。

内容的提问来源于stack exchange,提问作者user14016240

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 09:45:02