2

I have one activity, in which i have opened one url in to custom tab. Is there any way to get callback from Custom Tab? Opened the url in Custom Tab and wants the callback from that url. Thanks in Advance.

Mohini Thakkar
  • 166
  • 3
  • 7
  • Did you check [this](https://stackoverflow.com/questions/41010017/callback-on-dismiss-of-chrome-custom-tabs)? – Piyush Jan 10 '19 at 11:23
  • Yes,but it's not appropriate answer. @Piyush – Mohini Thakkar Jan 10 '19 at 11:31
  • Are you able to know then your url completely loaded? If you'r then you can use interface or you can simply call child activity using _startActivityForResult_ – Piyush Jan 10 '19 at 11:34
  • No, i just want the call back url same as webview gives to us.Like in Webview we are using Webview Client to get call back url.In webview there is a method named shouldOverrideUrlLoading gives us call back from browser. So, is there any way to get call back from Custom Tab. @Piyush – Mohini Thakkar Jan 10 '19 at 11:37
  • getting result in onActivityResult after i press back, not automatically. – Mohini Thakkar Jan 10 '19 at 11:40
  • Okay so do you want that when you url loaded in tabs after that should it automatically close with some callback as webviewClient does for _pageFinished_? – Piyush Jan 10 '19 at 11:41
  • I have to use custom tabs instead of webview, because webview can't able to handle a webpage that contains social login.Please help me out in this. @Piyush – Mohini Thakkar Jan 10 '19 at 11:42
  • Yes sure i will help you. !Okay so do you want for _customTab_ that when you url loaded in tabs after that should it automatically close with some callback as webviewClient does for pageFinished? – Piyush Jan 10 '19 at 11:43
  • Yes, exactly what you understand. @Piyush – Mohini Thakkar Jan 10 '19 at 11:43
  • Yeah. I think this is what you need [check](https://guides.codepath.com/android/Chrome-Custom-Tabs) – Piyush Jan 10 '19 at 11:46
  • I have to develop a demo with Pinterest login. As pdk is now deprecated, i have to use OAuth to develope a demo.I have opened that url in custom tab, but custom tab is not giving me call back after successful login.Thanks in advance. – Mohini Thakkar Jan 10 '19 at 11:48
  • As i know that with custom tab user need a user interaction for closing tab. You can implement broadcast receiver and also as i said earlier to use both options. – Piyush Jan 10 '19 at 11:53
  • [This](https://stackoverflow.com/questions/33795847/how-to-close-chrome-custom-tabs?rq=1) is the best way to do close tab automatically. CustomTab doesn't provide any callback which indicate that you'r url has been loaded completely and you get call back. Sure you will not. Without user interaction it is not possible. If you want to close automatically then i have mentioned link in my comment! – Piyush Jan 10 '19 at 12:07
  • Ok, let me try. Thanks – Mohini Thakkar Jan 10 '19 at 12:09
  • Okay. try it and give feedback. – Piyush Jan 10 '19 at 12:13
  • NOT WORKING AT ALL!!! @Piyush – Mohini Thakkar Jan 10 '19 at 12:19
  • Have you done same thing as mentioned in code? – Piyush Jan 10 '19 at 12:20
  • I have done same as posted on that answer, but didn't get call back in broadcast receiver. – Mohini Thakkar Jan 10 '19 at 12:35
  • Okay. No issue. I will post solution – Piyush Jan 10 '19 at 12:55
  • Yes, please as soon as possible. – Mohini Thakkar Jan 10 '19 at 13:05

1 Answers1

1

Unfortunately No! The custom chrome tabs are part of Chrome browser and need chrome browser to be installed on the target device as they use the same activity. But You have few alternative options to get the control back to your app -

  1. Implement a custom deeplink your app recognizes and the Url which is opened in the chrome tabs loads that deeplink when it finishes its work and needs to close itself. The deeplink when loaded by the chrome tab, will fire an intent which could be accepted by either the chrome browser or your app only. The user will get the choices to choose one from. But this mechanism is possible only if you have server side control of the web page you are trying to load in the chrome tabs.

  2. Let the user close the chrome tab by himself by clicking on the back arrow button or an action button you could add while building the Chrome tabs intent.

  3. Use webview inplace of Chrome tabs and get control of the entire web experience. But with this full control will come greater responsibilites too, as via webview you can easily intercept user's data, ignore his clicks or redirect him anywhere. If its your own website or a some local web content you need to display, go with webview, else go with chrome tabs.

Have a look at this example to get an idea of what could be customized with the custom tabs.

rupesh
  • 129
  • 1
  • 5
  • I don't wants to use deep linking. Is there any way to get callback? – Mohini Thakkar Jan 10 '19 at 12:03
  • I'm afraid no :( – rupesh Jan 10 '19 at 12:28
  • Implemented with Deep Linking.Is there any way to open my app directly?Because there is two option available either crome or in app.How can i open my app directly without showing that popup either app or crome? Thanks in advance. @rupesh – Mohini Thakkar Jan 11 '19 at 05:52
  • I'm afraid there's no way to ambiguation dialog below API level 23. At API level 23 and above, you can use app linking - https://developer.android.com/about/versions/marshmallow/android-6.0#app-linking – rupesh Jan 11 '19 at 11:01