Android
2018.09.23 / 16:17

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

hangawee
추천 수 142

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;
}
});