Facebook like confirmation opens confirm_widget in new window. So your webview should support Multiple Window opening. for this setJavaScriptCanOpenWindowsAutomatically(true) and setSupportMultipleWindows(true) for your webview-
private void setUpWebView() {
likeWebView = new WebView(getContext());
likeWebView.setWebViewClient(new FacebookWebViewClient());
likeWebView.setWebChromeClient(new MyChromeClient());
final WebSettings webSettings = likeWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setSupportMultipleWindows(true);
String url = getFacebookLikeUrl();
likeWebView.loadUrl(url);
likeWebView.setLayoutParams(FILL);
mContent.addView(likeWebView);
}
Facebook like confirmation calls onCreateWindow() method. SO override the onCreateWindow method in WebChromeClient -
final class MyChromeClient extends WebChromeClient {
// Add new webview in same window
@Override
public boolean onCreateWindow(WebView view, boolean dialog,
boolean userGesture, Message resultMsg) {
WebView childView = new WebView(getContext());
childView.getSettings().setJavaScriptEnabled(true);
childView.setWebChromeClient(this);
childView.setWebViewClient(new FacebookWebViewClient());
childView.setLayoutParams(FILL);
mContent.addView(childView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(childView);
resultMsg.sendToTarget();
return true;
}
// remove new added webview whenever onCloseWindow gets called for new webview.
@Override
public void onCloseWindow(WebView window) {
mContent.removeViewAt(mContent.getChildCount() - 1);
}
}
confirm_widget for like calls onCloseWindow when user click either Like or Cancel. On this method remove last added webview.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…