gpt4 book ai didi

android - 人行横道:XWalkUIClient.onCreateWindowRequested() :如何获取请求的 url?

转载 作者:行者123 更新时间:2023-11-30 01:18:47 25 4
gpt4 key购买 nike

每当某些 javascript 代码在人行横道 web View 中执行“window.open()”时,我想在 Android 中打开默认浏览器。

我创建了一个扩展 XWalkUIClient 并覆盖 onCreateWindowRequested() 的类.当调用 window.open() 时调用此方法,这是所需的行为。但是,我不知道如何获取调用 window.open() 的 url 参数。有谁知道我怎样才能检索到 url?

获得网址后,我想用以下代码打开此网址:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));

最佳答案

您不能直接访问该 url,但是使用临时 XWalkViewonCreateWindowRequested 中的自定义 XWalkUIClient,您可以实现您想要的之后。

下面的代码示例显示了如何访问 onCreateWindowRequested 中的 url:

xWalkView.setUIClient(new XWalkUIClient(xWalkView) {
@Override
public boolean onCreateWindowRequested(XWalkView view, InitiateBy initiator, final ValueCallback<XWalkView> callback) {
// Create a temporary XWalkView instance and set a custom XWalkUIClient
// to it with the setUIClient method. The url is passed as a parameter to the
// XWalkUIClient.onPageLoadStarted method.
XWalkView tempView = new XWalkView(getActivity());
tempView.setUIClient(new XWalkUIClient(tempView) {
@Override
public void onPageLoadStarted(XWalkView view, String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
});

// Return the temporary XWalkView instance with the callback to start the page
// load process in tempView.
callback.onReceiveValue(tempView);
return true;
}
});

关于android - 人行横道:XWalkUIClient.onCreateWindowRequested() :如何获取请求的 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37424024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com