Android 应用程序链接多个 Intent 过滤器主机和 list 合并不起作用

标签 android android-intent deep-linking

我正在处理构建变体,并希望根据变体捕获其他链接。我希望所有变体都从主机 1 捕获链接,所以我在我的主 AndroidManifest.xml 文件中声明了一个 intent-filter ,如下所示:

<activity android:name=".activity.DeepLinkActivity"
android:noHistory="true">
    <intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <category android:name="android.intent.category.DEFAULT"/>

    <data android:host="hostOne.com" android:path="/page.aspx" android:scheme="http"/>

    </intent-filter>
</activity> 

我还为其他变体生成部分 list ,例如 hostTwo.com,如下所示:

<?xml version="1.0" encoding="UTF-8"?><manifest package="com.package.my.domain">
  <application xmlns:android="http://schemas.android.com/apk/res/android" android:name="AlarmMobile">
    <activity android:name=".activity.DeepLinkActivity">
      <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:scheme="http://" android:host="hostTwo.com" android:path="/page.aspx"/>
      </intent-filter>
    </activity>
  </application>
</manifest>

它根据构建变体放置在一个适当命名的文件夹中 (based upon the documentation here) Android Studio 的合并 list View 显示主机二的 intent-filter 已添加到最终合并的 list 中,但是,模拟器或实际设备无法捕获为第二个主机准备的 Intent 。

我正在命令提示符中生成这样的 Intent :

adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "http://hostone.com/page.aspx"

它适用于 hostone,但正在做

adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "http://hosttwo.com/page.aspx"

将启动浏览器,因为应用无法捕获它。

Android 应用程序链接是否仅适用于一个主机名?还有什么我可以尝试的吗?

最佳答案

我发现部分 list 不正确。在intent-filterdata标签,android:scheme="http://"由于尾随 :// 而无效.

根据 google's documentation , Android 构建 intent-filter URI 像这样:<scheme>://<host>:<port>/<path>所以在声明中包含它是不必要的。

将我的声明更改为 android:scheme="http" 之后合并继续成功,操作系统尝试验证部分 list 中定义的链接!

更正了部分 list :

<?xml version="1.0" encoding="UTF-8"?><manifest package="com.package.my.domain">
  <application xmlns:android="http://schemas.android.com/apk/res/android" android:name="AlarmMobile">
    <activity android:name=".activity.DeepLinkActivity">
      <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:scheme="http" android:host="hostTwo.com" android:path="/page.aspx"/>
      </intent-filter>
    </activity>
  </application>
</manifest>

关于Android 应用程序链接多个 Intent 过滤器主机和 list 合并不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42348145/

相关文章:

java - Android 上的方法性能

java - FTPClient 无法打开文件,没有那个文件或目录

android - 如何处理用户对 ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS 的回答?

ios - 从应用程序委托(delegate)路由到特定的 View Controller 。 swift

手机上的 JavaScript keydown

android - 如何从小部件启动配置 Activity ?

java - 使用 Intent 将用户从 Adapter 发送到另一个 Activity

ios - nw_read_request_report [C9] 接收失败,错误 "Software caused connection abort"

ios - 如何在 iOS 中实现延迟深度链接

android - 没有向 HAL 提供足够的数据,预期位置