12

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))
user1552050
  • 121
  • 1
  • 5

1 Answers1

3

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.

Smile
  • 207
  • 4
  • 13
  • Thanks for reply but this won't work in my scenario. What I currently do is: 1. Open login url from webview in chrome browser 2. After login is completed I'm redirected back to my single webview host from 3rd party provider with auth token - which always redirects to "https://my-host/auth-token" after I changed the https scheme it will be never opened in my native app. And this works as expected, just doesn't work when I replace chrome browser to custom tabs – user1552050 Jul 11 '18 at 12:41
  • this is great hint, I was struggling with this. changed my scheme to app-id (com.company.appname). updated redirect url in keycloak also. and it worked. – Developine Aug 26 '20 at 09:22
  • i changed mine from https to something else and it worked – Kurt Capatan Feb 23 '23 at 19:48