Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement URL change listener in chrome custom tabs?

Is there any listener in which we can know that URL has been changed in chrome custom tabs.

String url = ¨https://paul.kinlan.me/¨;
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));

I am opening this link using chrome custom tabs. I have to snip each url change and open appropriate activity in android

like image 872
John Avatar asked May 25 '18 09:05

John


2 Answers

Unfortunately, it is not possible

In order to safeguard the user's privacy when navigating, the URLs are not automatically sent to the host app through the navigation events.

It is possible to get the URL as a result of the user clicking on the custom action button or on one of the buttons on the secondary toolbar.

This piece of code shows how to setup the custom action button and this code shows how to retrieve the URL inside a BroadcastReceiver, invoked by the CustomAction.

like image 200
andreban Avatar answered Nov 04 '22 02:11

andreban


If you know the host you can setup an IntentFilter

<intent-filter>
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />
     <category android:name="android.intent.category.BROWSABLE" />

     <data
         android:host="paul.kinlan.me"
         android:scheme="https"/>

</intent-filter>

for any Activity you want to handle this URL in. It will start in onCreate with an argument arguments?.get("_uri") as? Uri or something similar, which you can further parse and see where the user has gone to.

like image 1
Yurets Avatar answered Nov 04 '22 02:11

Yurets