简体   繁体   English

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

[英]Android app link not working in android 12 always opening in browser

I have hosted assetlinks file into our domain https://ourdomain/.well-known/assetlinks.json And also verified this using https://developers.google.com/digital-asset-links/tools/generator and from android studio's App Links Assitant and got verified status from both the ways.我已经将 assetlinks 文件托管到我们的域 https://ourdomain/.well-known/assetlinks.json 并且还使用https://developers.google.com/digital-asset-links/tools/generator和 android studio 验证了这一点App Links Assitant 并从两种方式获得验证状态。 But when i am sharing debug APK for testing it's always opening in browser.但是当我共享调试 APK 进行测试时,它总是在浏览器中打开。 I also tried uploading on app store and downloaded from there for testing but it always open in browser.我也尝试在应用商店上传并从那里下载进行测试,但它总是在浏览器中打开。

Note: for debug build used my laptop SHA-256 and once app live on play store changed SHA ( got SHA-256from By going to Application Dashboard in Play Console then Release Management --> App Signing ) on hosted assetlinks file into our domain https://ourdomain/.well-known/assetlinks.json注意:对于调试版本,我使用了我的笔记本电脑 SHA-256,一旦应用程序在 Play 商店上线,就将托管资产链接文件上的 SHA 更改为 SHA(通过转到 Play 控制台中的应用程序仪表板然后发布管理 --> 应用程序签名获得 SHA-256)到我们的域 https ://ourdomain/.well-known/assetlinks.json

Below is the code used in the manifest file.下面是清单文件中使用的代码。


     <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>

I have same problem and solved by going to app info setting -> set as default ->support web addresses and you will see your short link so turn it on and it will work;)我有同样的问题,通过进入应用程序信息设置解决了 -> 设置为默认 -> 支持 web 地址,你会看到你的短链接,所以打开它就可以了;)

Update:更新:

as every one said its not a programmatically way so the best way is that link below said 正如每个人都说它不是一种编程方式,所以最好的方法是下面的链接说

Deep-links are working in Android 11 or before but on Android 12 it isn't. Deep-linksAndroid 11或更早版本中有效,但在Android 12中无效。

But even after adding assetlinks.json file and adding all the intent-filters .但即使在添加assetlinks.json文件并添加所有intent-filters之后。 Android 12 still isn't detecting deep-links . Android 12仍然没有检测到deep-links In Android-Manifest file turns out that scheme's tag is need to be separated from the data tag like this: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" />

In my case, the app is working in android 11, but it doesn't work in android 12 when the app is compiled and built with android studio.在我的情况下,该应用程序在 android 11 中运行,但是当应用程序使用 android 工作室编译和构建时,它在 android 12 中不起作用。

I tested the production app;我测试了生产应用程序; it works fine with the app link.它适用于应用程序链接。

For development build, I have to go to App info -> Open by default -> Add link -> check off all the available links对于开发版本,我必须 go 到 App info -> 默认打开 -> 添加链接 -> 检查所有可用链接

This seems only happen with development builds;这似乎只发生在开发版本中; the apps installed from Google app store automatically has all the links selected.从 Google 应用商店安装的应用会自动选择所有链接。

After adding assetlinks.json in domain you have to reinstall app (just uninstall the app and install again) that will work在域中添加assetlinks.json 后,您必须重新安装应用程序(只需卸载应用程序并重新安装)才能正常工作

In my case problem was with inconsistent between SHA Signatures in store build and https://ourdomain/.well-known/assetlinks.json, that's why deep links were disabled by default on Android 12, for fixing it we can connect our phone with problem build to Android studio and run this command:在我的情况下,问题是商店构建中的 SHA 签名与 https://ourdomain/.well-known/assetlinks.json 之间不一致,这就是为什么在 ZE84E30B9390CDB64DB6DB12C9AB8 上默认禁用深度链接的原因问题构建到 Android 工作室并运行以下命令:

adb shell pm get-app-links com.your_app_package_name

as a result you should see something like this:结果,您应该会看到如下内容:

com.your_app_package_name:
ID: .....
Signatures: [AB:CD:EF:HI:GK...]
Domain verification state:
   your_domain.com legacy_failure

next you need to check whether the signature fingerprints is included in your https://ourdomain/.well-known/assetlinks.json, in my case it doesn't, also keep in mind that in assetlinks.json file can be couple of signatures for example for debug, alpha, beta and production builds, it should looks like below:接下来您需要检查签名指纹是否包含在您的 https://ourdomain/.well-known/assetlinks.json 中,在我的情况下它没有,还请记住,在assetlinks.Z466DEEC76ECDF63FCA65D387 文件中可以是一对例如调试、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..."]
        }
    }
]

This approach should solve deeplink issue on android 12 above此方法应解决上述 android 12 上的深度链接问题

Automatic approach自动进近

skip step 1 & 2跳过第 1 步和第 2 步

Go to Tools/ App Link Assistance and follow the step on the image Go 到工具/应用链接帮助并按照图像上的步骤操作

在此处输入图像描述

Manual Approach手动方法

Step 1: update all intent filters that can respond to an HTTP link with the android:autoVerify="true"第 1 步:使用 android:autoVerify="true" 更新所有可以响应 HTTP 链接的意图过滤器

<activity
android:name="com.example.MainActivity">
    <intent-filter android:autoVerify="true">

    </intent-filter>
</activity>

Step 2: Create the assetlinks.json file and update your package and sha key第 2 步:创建assetlinks.json 文件并更新您的 package 和 sha 密钥

  //update package_name and sha256_cert_fingerprints with yours
[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
  "namespace": "android_app",
  "package_name": "Your App’s package name", 
  "sha256_cert_fingerprints":  ["Your App’s SHA256 finger print"]
 }

}] }]

Step 3: Publishing the JSON verification file Work with your infrastructure team to deploy the assetlinks.json file to the host第 3 步:发布 JSON 验证文件 与您的基础架构团队合作,将assetlinks.json 文件部署到主机

https://your domain.com/.well-known/assetlinks.json

Be sure of the following:请确保以下几点:

  • The assetlinks.json file is served with content-type application/json. assetlinks.json 文件使用内容类型应用程序/json 提供。
  • The assetlinks.json file must be accessible over an HTTPS connection, regardless of whether your app's intent filters declare HTTPS as the data scheme.无论您的应用的意图过滤器是否将 HTTPS 声明为数据方案,assetlinks.json 文件都必须可通过 HTTPS 连接访问。
  • The assetlinks.json file must be accessible without any redirects (no 301 or 302 redirects). assetlinks.json 文件必须可以在没有任何重定向的情况下访问(无 301 或 302 重定向)。
  • Do not publish your app with dev/test URLs in the manifest file that may not be accessible to the public (such as any that are accessible only with a VPN).不要在清单文件中发布您的应用程序,其中包含公共可能无法访问的开发/测试 URL(例如只能通过 VPN 访问的任何内容)。 A work-around in such cases is to configure build variants to generate a different manifest file for dev builds.在这种情况下,一种解决方法是配置构建变体以为开发构建生成不同的清单文件。

This fixed it for me:这为我修复了它:

<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="my.page.link"  />
    <data android:scheme="https" />
        
</intent-filter>

Notice: android:autoVerify="true"注意: android:autoVerify="true"

The weird thing about this is only broke on certain Android phones, and wasn't necessarily consistent across API versions.奇怪的是,仅在某些 Android 手机上出现问题,并且在 API 版本中不一定一致。 Pixel 4 on API 33 worked fine without this fix and didn't work with Pixel 6 on API 33. What can ya do. API 33 上的像素 4 在没有此修复的情况下工作正常,并且不适用于 API 33 上的像素 6。你能做什么。

In my case after doing the above (debug/release SHA-256 keys in assetlinks, separate the scheme tag) the final culprit turned out to be the "path" tag.在我的情况下,在完成上述操作(调试/发布资产链接中的 SHA-256 键,分离方案标签)后,最终的罪魁祸首竟然是“路径”标签。 For some reason the verification process does not include the tag even though this has always been there in the app and used to work prior to Android 12. Not a big deal in my app since I was ignoring the path anyway.由于某种原因,验证过程不包括标签,即使它一直存在于应用程序中,并且在 Android 12 之前曾经工作过。在我的应用程序中没什么大不了的,因为无论如何我都忽略了路径。

Before (not working):之前(不工作):

<data android:host="dl.example.com"
      android:path="/test" />
<data android:scheme="https" />

After (working):之后(工作):

<data android:host="dl.example.com"/>
<data android:scheme="https"/>

Hope it helps someone希望它可以帮助某人

Follow these steps:按着这些次序:

Step 1:第1步:

Add android:autoVerify="true" to your intents-filter.android:autoVerify="true"添加到您的意图过滤器。

Step 2:第2步:

Move the android:scheme to separate data tagandroid:scheme移动到单独的data标签

So now your intents-filter in manifest looks like this:所以现在manifest中的intents-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:host="websiteUrl"
        android:pathPrefix="/" />
    <data
        android:scheme="https" />
    <!-- note that the leading "/" is required for pathPrefix-->
</intent-filter>

Step 3:第 3 步:

Add your Digital Asset Links JSON file to following url:将您的数字资产链接 JSON 文件添加到以下 url:

https://{yourdomain.name}/.well-known/assetlinks.json https://{您的域名.name}/.well-known/assetlinks.json

Note :- For production app make sure you use the digital asset links JSON file generated by Play console.注意:- 对于生产应用,请确保使用 Play 控制台生成的数字资产链接 JSON 文件。 You can find it at你可以在

Play console -> Your App -> Setup (Side menu option) -> App Integrity -> App signing (scroll to the bottom)播放控制台 -> 您的应用程序 -> 设置(侧面菜单选项)-> 应用程序完整性 -> 应用程序签名(滚动到底部)

Step 4:第四步:

Verify that all the steps are correctly implemented by manually running app link validation using these commands - https://developer.android.com/training/app-links/verify-android-applinks#manual-verification通过使用这些命令手动运行应用程序链接验证来验证所有步骤是否正确实施 - https://developer.android.com/training/app-links/verify-android-applinks#manual-verification

Step 5:第 5 步:

If your links were shown as verified in step 4 then now install the app on device and wait for atleast 2-3 minutes before clicking on any app links because in this time Android will verify your app links by reading your manifest file and the digital assets JSON file that you uploaded on your website.如果您的链接在第 4 步中显示为已验证,那么现在在设备上安装该应用程序并等待至少 2-3 分钟,然后再单击任何应用程序链接,因为此时 Android 将通过读取您的清单文件和数字资产来验证您的应用程序链接您在网站上上传的 JSON 文件。

After you have waited 2-3 minutes, now you can click on your app link and it should open your app.等待 2-3 分钟后,现在您可以单击您的应用程序链接,它应该会打开您的应用程序。

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM