我在android中使用Chrome customTabs,我需要实时获取当前的URL,这意味着一旦它发生变化,就会触发回调。
我发现了两件事可能有用。
CustomTabsCallback.onNavigationEvent(int navigationEvent, Bundle extras);
当 URL 更改或刷新时,它可以返回导航事件代码。如何从 CustomTabsClient 获取 URL 更改 https://stackoverflow.com/questions/33343917/how-to-get-url-change-from-customtabsclient
BroadcastReceiver + PendingIntent可以通过点击获取url。https://gist.github.com/YeWang0/d344618bf8ac269dc3c39fa45214cf8b#handle-actions-using-a-broadcastreceiver https://gist.github.com/YeWang0/d344618bf8ac269dc3c39fa45214cf8b#handle-actions-using-a-broadcastreceiver
我在想,是否可以在 onNavigationEvent() 调用时伪造一个点击事件,然后我应该能够实时获取 URL。
这不可能
为了在导航时保护用户的隐私,URL 不会通过导航事件自动发送到主机应用程序。
用户单击自定义操作按钮或辅助工具栏上的按钮之一即可获取 URL。
This https://github.com/GoogleChrome/custom-tabs-client/blob/master/demos/src/main/java/org/chromium/customtabsdemos/CustomUIActivity.java#L113-L122一段代码显示了如何设置自定义操作按钮和this https://github.com/GoogleChrome/custom-tabs-client/blob/master/demos/src/main/java/org/chromium/customtabsdemos/ActionBroadcastReceiver.java#L34代码展示了如何检索由 CustomAction 调用的 BroadcastReceiver 内的 URL。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)