简体   繁体   English

Android应用链接无法与Chrome自定义标签一起使用

[英]Android app links not working with Chrome Custom Tabs

I have application which use app links for login in the browser outside of the app and is redirected back after login is completed. 我有应用程序使用应用程序链接在应用程序外部的浏览器中登录,并在登录完成后重定向回来。 This works fine with android native browsers but fails when I'm using Chrome Custom Tabs. 这适用于Android原生浏览器但在我使用Chrome自定义选项卡时失败。 User is logged in custom tabs and not redirected back to the app, so I wonder if is it possible to use app links with custom tabs in the same way as with the native browsers? 用户登录自定义选项卡,而不是重定向回应用程序,所以我想知道是否可以像使用本机浏览器一样使用自定义选项卡的应用程序链接?

manifest configuration 清单配置

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

<data
    android:host="my-host"
    android:scheme="https" />

working implementation in native browsers 在本机浏览器中实现工作

val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
ContextCompat.startActivity(context, intent, null)

failing redirect using chrome custom tabs 使用Chrome自定义标签失败重定向

val customTabsIntent = CustomTabsIntent.Builder()
    .build()

customTabsIntent.launchUrl(context, Uri.parse(url))

Because your deeplink url is like that of a website, the Chrome Custom Tab will always try to load it as a webpage instead of redirecting. 由于您的深层链接网址与网站类似,因此Chrome自定义标签会始终尝试将其作为网页加载,而不是重定向。 What you could do is use a scheme not commonly supported by a browser like app-name:// then your host could be redirect-to so what this would play out to be would be 您可以做的是使用app-name://类的浏览器通常不支持的方案app-name://然后您的主机可以redirect-to所以这将是什么样的将是

 <data
  android:host="redirect-to"
  android:scheme="app-name" />

This way only your app, will be the one to resolve this url. 这样只有你的应用程序才能解析这个网址。 But take note when you use this type of url, it may not appear as a link in some apps like e-mails. 但请注意,当您使用此类型的网址时,它可能不会显示为某些应用程序(如电子邮件)中的链接。

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

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