Is it possible to get the current URL of a Android Chrome CustomTab in real time?

一个人想着一个人 提交于 2019-12-08 07:44:20

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!