1

I'm launching Chrome Custom Tabs using a similar function as below but I'm always getting the activity result as canceled which makes sense when clicking the close icon. but isn't really helping when I want to differentiate between a redirection to the app and the close icon click. is there a way to set the activity result for the custom tabs?

   fun launchURL(context: Context, url: String, requestCode: Int) {
       val builder = CustomTabsIntent.Builder()
       val customTabsIntent = builder.build()
       customTabsIntent.intent.data = Uri.parse(url)
       (context as Activity).startActivityForResult(customTabsIntent.intent, requestCode)
}
Peter Helmy
  • 93
  • 2
  • 7
  • What do you mean by "redirection to the app"? Are you referring to handling deeplink in custom tab? – Jakoss Feb 16 '22 at 13:37
  • @Jakoss yes. I just found CustomTabsCallback, but I thought there would be a way to set the onActivityResult result in a different way than using the callback – Peter Helmy Feb 16 '22 at 13:41

1 Answers1

2

AFAIK you cannot listen for specific url running in custom tab, so the only way you can handle the redirection to the app is to handle a deeplink. When user clicks the deeplink in the custom tab it will be treated like a normal deeplink in the system. If your app is registered to handle it - it will.

Jakoss
  • 4,647
  • 2
  • 26
  • 40
  • [I found here info](https://stackoverflow.com/questions/34859497/chrome-custom-tabs-not-opening-other-apps), which says: "Custom Chrome Tabs just support custom schemes, http/https won't be launched as an application intent." Is that true? Is there really no chance to use http/s url? – smbdy Jun 08 '22 at 12:23
  • well, it seems like an odd choice there for google, but if they say so - you probably don't have any other options. Honesly, chrome tabs are for basic scenarios. You probably just need to go with WebView – Jakoss Jun 08 '22 at 13:05