[Android] WebView Open target _blank links in WebView with external browser , target _blank 브라우저로 열기

북마크 추가

webview에서 target="_blank" 링크를 열때 webview내에서가  아닌 외부의 브라우저로 여는 방법이다.

 

1. onCreate에 WebView설정

 

WebSettings set = mWebView.getSettings();
set.setSupportMultipleWindows(true);

 

2. onCreateWindow Override

 

mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg)
{
WebView newWebView = new WebView(MainActivity.this);
view.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
return true;
}
});

 

HKH
2016-05-17 16:35
SHARE
keyboard_arrow_left
keyboard_arrow_up