Reputation: 14907
I want to open the default browser in Android whenever some javascript code executes 'window.open()' in a crosswalk webview.
I have created a class that extends XWalkUIClient
and overrides onCreateWindowRequested(). This method gets called when window.open()
is called which is the desired behaviour. However, I don't know how to get the url parameter that window.open()
is called with. Does anyone know how I can get retrieve the url?
Once I get the url, I want to open this url with the following code:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
Upvotes: 1
Views: 589
Reputation: 26
You cannot access the url directly, but with a temporary XWalkView
and a custom XWalkUIClient
in onCreateWindowRequested
, you can achieve what you're after.
The following code example shows how to access the url in onCreateWindowRequested
:
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;
}
});
Upvotes: 1