Web视图URL在android 5.1.1中运行良好,但在4.4.2版本中运行不佳,仅显示空白屏幕。这是我的代码
public class WebViewTwo extends Activity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web_view_two);
webView = (WebView)findViewById(R.id.webView2);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.setWebViewClient(new WebViewClient());
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("www.google.co.in");
}
这是我的日志错误
07-21 12:26:13.053 2089-2104/com.ccc.dar E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
07-21 12:26:13.064 2089-2104/com.ccc.dar E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
07-21 12:26:13.167 2089-2104/com.ccc.dar E/eglCodecCommon﹕ **** ERROR unknown type 0x79edaef5 (glSizeof,72)
07-21 12:26:13.184 2089-2104/com.ccc.dar E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
07-21 12:26:13.194 2089-2104/com.ccc.dar E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
07-21 12:26:13.214 2089-2096/com.ccc.dar W/art﹕ Suspending all threads took: 22.429ms
07-21 12:26:13.238 2089-2104/com.ccc.dar E/eglCodecCommon﹕ **** ERROR unknown type 0x79edaef5 (glSizeof,72)
07-21 12:26:13.435 2089-2104/com.ccc.dar E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
07-21 12:26:13.457 2089-2104/com.ccc.dar E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
07-21 12:26:13.499 2089-2101/com.ccc.dar I/art﹕ Background sticky concurrent mark sweep GC freed 1125(118KB) AllocSpace objects, 1(16KB) LOS objects, 0% free, 5MB/5MB, paused 2.405ms total 145.580ms
07-21 12:26:13.584 2089-2104/com.ccc.dar E/eglCodecCommon﹕ **** ERROR unknown type 0x79edaef5 (glSizeof,72)
07-21 12:26:44.980 2089-2096/com.ccc.dar W/art﹕ Suspending all threads took: 11.554ms
替换代码webView.setWebChromeClient(new WebChromeClient());使用webView.setWebChromeClient(新的MyWebChromeClient());添加以下代码-
private class MyWebChromeClient extends WebChromeClient {
@Override
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
Log.d(TAG, message + " -- From line "
+ lineNumber + " of "
+ sourceID);
}
}
检查控制台日志。还要检查你的url是http还是https,这样可以进行相应的处理。这件事也发生在我身上一次,发现了网页的问题。
经过研究,我得到了答案,现在它在4.4.2上运行顺利。
public class WebViewTwo extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web_view_two);
WebView webView = (WebView) findViewById(R.id.webView2);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new HelloWebViewClient());
webView.loadUrl("http://www.google.co.in");
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}}