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

Android Intent Filter未完整匹配URI主机,如何精准指定域名?

解决方案

问题出在你当前的<intent-filter>配置中,多个<data>标签是独立的匹配规则,而非组合生效。比如单独的<data android:scheme="http">会匹配所有HTTP协议的链接(无论主机名是什么),这就是为什么dev.example.com这类链接也会触发应用选择提示。

要实现仅允许app.dev.example.com/...的链接,你需要将scheme和host属性合并到同一个<data>标签中,确保每个匹配规则同时限定协议和主机名:

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <!-- 每个scheme与host绑定,形成完整匹配规则 -->
    <data android:scheme="http" android:host="app.dev.example.com"/>
    <data android:scheme="https" android:host="app.dev.example.com"/>
    <data android:scheme="custom-scheme" android:host="app.dev.example.com"/>
</intent-filter>

关键说明:

  • android:autoVerify="true":启用Android App Links验证,验证通过后系统会直接用你的应用打开匹配链接,无需显示选择器;同时确保只有你验证过的域名(app.dev.example.com)会被匹配。
  • 每个<data>标签同时指定scheme和host,确保只有同时满足这两个条件的链接才会被应用处理,dev.example.com或example.com的链接因host不匹配,不会触发应用。

修改后的完整Manifest配置(仅调整对应的intent-filter部分):

<manifest package="com.e.axamplepp"
  xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

  <application android:label="@string/app_name" android:icon="@mipmap/launcher_icon">
    <activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">

      <meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme"/>
      <meta-data android:name="flutter_deeplinking_enabled" android:value="true"/>
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>

      <!-- 修改后的intent-filter -->
      <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="http" android:host="app.dev.example.com"/>
        <data android:scheme="https" android:host="app.dev.example.com"/>
        <data android:scheme="custom-scheme" android:host="app.dev.example.com"/>
      </intent-filter>

    </activity>

    <meta-data android:name="flutterEmbedding" android:value="2"/>
  </application>

  <queries>
    <intent>
      <action android:name="android.intent.action.VIEW"/>
      <data android:scheme="https"/>
    </intent>
  </queries>
</manifest>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 23:05:17