I am using Chrome customTabs in android and I need to get the current URL in real time, which means once it changed, trigger a callback.
I found two things that may be useful.
CustomTabsCallback.onNavigationEvent(int navigationEvent, Bundle extras); It can return a navigation event code when URL changed or refreshed. How to get Url change from CustomTabsClient
BroadcastReceiver + PendingIntent can get url by clicking. https://gist.github.com/YeWang0/d344618bf8ac269dc3c39fa45214cf8b#handle-actions-using-a-broadcastreceiver
I am thinking, is it possible to fake a click event when onNavigationEvent() called, then I should be able to get the URL in real time.
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.
来源:https://stackoverflow.com/questions/49583579/is-it-possible-to-get-the-current-url-of-a-android-chrome-customtab-in-real-time