简体   繁体   English

如何在 Chrome 自定义选项卡中实现 URL 更改侦听器?

[英]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.是否有任何侦听器可以让我们知道 chrome 自定义选项卡中的 URL 已更改。

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.我正在使用 chrome 自定义选项卡打开此链接。 I have to snip each url change and open appropriate activity in android我必须剪下每个 url 更改并在 android 中打开适当的活动

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.为了在导航时保护用户的隐私,URL 不会通过导航事件自动发送到宿主应用程序。

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.可以通过用户单击自定义操作按钮或辅助工具栏上的按钮之一来获取 URL。

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. 这段代码展示了如何设置自定义操作按钮, 这段代码展示了如何在由 CustomAction 调用的 BroadcastReceiver 中检索 URL。

If you know the host you can setup an IntentFilter如果你知道主机,你可以设置一个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对于您想要处理此 URL 的任何Activity 。它将从onCreate开始,并带有一个参数arguments?.get("_uri") as? Uri arguments?.get("_uri") as? Uri or something similar, which you can further parse and see where the user has gone to. arguments?.get("_uri") as? Uri或类似的东西,您可以进一步解析并查看用户去了哪里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM