Android 应用程序链接在 Android 12 中不起作用,始终在浏览器中打开

Asd*_*Asd 67 android deep-linking kotlin android-deep-link android-app-links

我已将 assetlinks 文件托管到我们的域 https://ourdomain/.well-known/assetlinks.json 并且还使用https://developers.google.com/digital-asset-links/tools/generator和 android studio验证了这一点应用程序链接助手并从这两种方式获得了验证状态。但是当我共享调试 APK 进行测试时,它总是在浏览器中打开。我还尝试在应用程序商店上传并从那里下载进行测试,但它总是在浏览器中打开。

注意:对于调试构建,使用了我的笔记本电脑 SHA-256,一旦 Play 商店上的应用程序将托管资产链接文件上的 SHA(通过转到 Play 控制台中的应用程序仪表板然后发布管理 --> 应用程序签名获得 SHA-256)更改为我们的域 https ://ourdomain/.well-known/assetlinks.json

以下是清单文件中使用的代码。


     <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="https"
                android:host="abc.test.com" />
        </intent-filter>
Run Code Online (Sandbox Code Playgroud)

Eri*_*Cen 27

就我而言,该应用程序可以在 android 11 中运行,但当使用 android studio 编译和构建该应用程序时,它无法在 android 12 中运行。

我测试了生产应用程序;它与应用程序链接配合得很好。

对于开发构建,我必须转到应用程序信息 -> 默认打开 -> 添加链接 -> 选中所有可用链接

这似乎只发生在开发版本中;从 Google 应用商店安装的应用程序会自动选择所有链接。


Ali*_*iei 13

我有同样的问题,并通过转到应用程序信息设置 - >设置为默认 - >支持网址来解决,您将看到您的短链接,因此将其打开,它将起作用;)

更新:

正如每个人所说,这不是一种编程方式,所以最好的方法是下面的链接

  • 相信我,从开发人员的角度来看,这不是解决问题的正确方法。用户中没有人会这样做,所以这是糟糕的用户体验。 (20认同)
  • 有什么编程解决方案吗? (4认同)

小智 12

Deep-links正在Android 11或之前工作,但Android 12不是。

但即使在添加assetlinks.json文件并添加所有intent-filters. Android 12仍然没有检测到deep-links。在Android-Manifest文件中事实证明,方案tag需要与数据标签分开,如下所示:

// OLD - Which is only working Android 11 or before

<data
  android:host="domain.name"
  android:pathPrefix="/videos"
  android:scheme="https" />

// NEW - Which is working on all including Android 12

<data android:scheme="https" />
<data
    android:host="domain.name"
    android:pathPrefix="/videos" />
Run Code Online (Sandbox Code Playgroud)

  • 这在我的情况下不起作用,我使用相同的 (17认同)

Bob*_*ter 11

您需要添加深度链接验证。请参阅https://doordash.engineering/2022/01/25/your-deep-links-might-be-broken-web-intents-and-android-12/

  • 从这篇文章中,我在我的意图过滤器中尝试了`android:autoVerify="true"`并修复了它 (2认同)

小智 9

Android 12之前,Deep link遵循标准实现,代码在Manifest中:

<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:scheme="https" 
    android:host="www.yourdomain.dev"
    android:pathPrefix="/set/v1" />
Run Code Online (Sandbox Code Playgroud)

Android 12之后,我们必须将autoVerify添加到intent-filter中:

<intent-filter android:autoVerify="true" tools:targetApi="m">
Run Code Online (Sandbox Code Playgroud)

并且必须通过将 assetlinks.json 添加到网站的 .wellknown 目录来验证网站(与 Apple 相同)

但是,最重要的是,您只能测试此构建并签署应用程序:构建 -> 生成签名包/APK

在开发过程中,您可以手动测试您的实现,启用设备上应用程序中的链接


Jay*_*hta 8

按着这些次序:

步骤1:

添加android:autoVerify="true"到您的意图过滤器。

第2步:

移动android:scheme到单独的data标签

所以现在你的intents-filter看起来manifest像这样:

<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:host="websiteUrl"
        android:pathPrefix="/" />
    <data
        android:scheme="https" />
    <!-- note that the leading "/" is required for pathPrefix-->
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

步骤3:

将您的数字资产链接 JSON 文件添加到以下网址:

https://{yourdomain.name}/.well-known/assetlinks.json

注意:- 对于生产应用程序,请确保使用 Play 控制台生成的数字资产链接 JSON 文件。您可以在以下位置找到它:

Play 控制台 -> 您的应用程序 -> 设置(侧面菜单选项) -> 应用程序完整性 -> 应用程序签名(滚动到底部)

步骤4:

使用这些命令手动运行应用程序链接验证来验证所有步骤是否正确实施 - https://developer.android.com/training/app-links/verify-android-applinks#manual-verification

第5步:

如果您的链接在步骤 4 中显示为已验证,那么现在在设备上安装该应用程序并等待至少 2-3 分钟,然后再单击任何应用程序链接,因为此时 Android 将通过读取您的清单文件和数字资产来验证您的应用程序链接您在网站上上传的 JSON 文件。

等待 2-3 分钟后,现在您可以单击应用程序链接,它应该会打开您的应用程序。

希望这可以帮助!


Ore*_*dil 7

就我而言,问题在于商店构建中的 SHA 签名与 https://ourdomain/.well-known/assetlinks.json 之间不一致,这就是 Android 12 上默认禁用深层链接的原因,为了修复它,我们可以将手机连接到问题构建到 Android studio 并运行以下命令:

adb shell pm get-app-links com.your_app_package_name
Run Code Online (Sandbox Code Playgroud)

结果你应该看到这样的东西:

com.your_app_package_name:
ID: .....
Signatures: [AB:CD:EF:HI:GK...]
Domain verification state:
   your_domain.com legacy_failure
Run Code Online (Sandbox Code Playgroud)

接下来您需要检查签名指纹是否包含在您的 https://ourdomain/.well-known/assetlinks.json 中,在我的情况下没有包含,还要记住 assetlinks.json 文件中可以有几个例如调试、alpha、beta 和生产版本的签名,它应该如下所示:

[
  {
   "relation": ["delegate_permission/common.handle_all_urls"],
    "target": {
     "namespace": "android_app",
     "package_name": "com.your_app_package_name",
     "sha256_cert_fingerprints" :["DE:BU:GS:HA:25:6...","PR:OD:SH:A:25:6..."]
        }
    }
]
Run Code Online (Sandbox Code Playgroud)