Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

customTabsIntent.launchUrl(context, Uri.parse(url))
like image 861
user1552050 Avatar asked Jul 09 '18 11:07

user1552050


1 Answers

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

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

like image 169
Smile Avatar answered Sep 19 '22 12:09

Smile