我想在新窗口上处理tel模式,但是在版本代码21下不应该调用OverrideUrlLoading(),高于21可以正常工作。
创建新窗口时,应调用shouldOverrideUrlLoading(),但单击
<a href='tel:00-000-000'/>
在从未调用过的新窗口中。
仅显示unknown_schema_error。
这是我的构建conf
compileSdkVersion 23
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
}
我这样重写ChromeClient.class中的onCreateWindow()。
WebView newWebView = new WebView(activityContext);
WebSettings wSettings = newWebView.getSettings();
String userAgent = wSettings.getUserAgentString();
wSettings.setUserAgentString(userAgent + " News1-Android");
wSettings.setJavaScriptEnabled(true);
wSettings.setBuiltInZoomControls(true);
wSettings.setUseWideViewPort(true);
wSettings.setLoadWithOverviewMode(true);
wSettings.setDomStorageEnabled(true);
wSettings.setSupportMultipleWindows(true);
wSettings.setJavaScriptCanOpenWindowsAutomatically(true);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.setAcceptThirdPartyCookies(newWebView, true);
wSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
newWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i("test",">>>>>>> "+url);
return super.shouldOverrideUrlLoading(view, url);
}
});
newWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onCloseWindow(WebView window) {
window.setVisibility(View.GONE);
mParentView.removeView(window);
mWebview.setVisibility(View.VISIBLE);
}
});
mWebview.setVisibility(View.GONE);
mParentView.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();