Webview Development
Following section is for Android webview Developers. Since pressing share in magazine requests to open new window, it is required to allow webview to handle this case.
For webview we need to enable following settings
WebView webView = new WebView(getContext());
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setSupportMultipleWindows(true);The next step should be actual handling of opening of the request new window. It's handled via WebChromeClient.onCreateWindow. Here some code example
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
WebView webView = new WebView(mContext);
//add webView to your view hierarchy
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(webView);
resultMsg.sendToTarget();
return true;
}
//Also don't forget to handle closing of the webview when page requested it in WebChromeClient.onCloseWindow.
//Handling of the URI related to specific app schema can be done in WebViewClient.shouldOverrideUrlLoading (looks like we have this as one of the share option).
//For example
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// if the url scheme is one of the following - do not override the url loading
if (URLUtil.isNetworkUrl(url.toLowerCase())) {
return false;
} else {
// try to launch app
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
return true;
}
}
Use video player in webview
Last updated