API 21 及更高版本中的 Android webview 加载失败 [英] Android webview loading fail in API 21 and above

查看:94
本文介绍了API 21 及更高版本中的 Android webview 加载失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 WebView 并加载页面的 Android 应用程序.此应用适用于运行 API 16 或更高版本的 Android 设备.

I have an Android application that uses WebView and load a page. This application works on Android devices running API 16 or above.

Android WebView 代码:

Android WebView Code:

String URL = "https://sandbox.napas.com.vn/gateway/message";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view);

    webview = (WebView) findViewById(R.id.webview);

    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setAllowFileAccess(true);
    webview.getSettings().setPluginState(PluginState.ON);
    webview.getSettings().setDomStorageEnabled(true);
    webview.getSettings().setAllowContentAccess(true);
    webview.getSettings().setAllowFileAccessFromFileURLs(true);
    webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

    webview.setWebChromeClient(new MyWebChromeClient());
    webview.loadUrl(URL);

    webview.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        }
    });
}

但 webview 加载页面为空并且有日志:

But webview load page empty and have logs:

E/libEGL(25467): validate_display:255 error 3008 (EGL_BAD_DISPLAY)
W/AudioCapabilities(25467): Unsupported mime audio/evrc
W/AudioCapabilities(25467): Unsupported mime audio/qcelp
W/VideoCapabilities(25467): Unrecognized profile 2130706433 for video/avc
W/AudioCapabilities(25467): Unsupported mime audio/amr-wb-plus
W/AudioCapabilities(25467): Unsupported mime audio/mpeg-L1
W/AudioCapabilities(25467): Unsupported mime audio/mpeg-L2
D/ConnectivityManager(25467): CallingUid : 10063, CallingPid : 25467
D/ConnectivityManager.CallbackHandler(25467): CM callback handler got msg 524290
W/AudioCapabilities(25467): Unsupported mime audio/x-ms-wma
W/AudioCapabilities(25467): Unsupported mime audio/x-ima
W/AudioCapabilities(25467): Unsupported mime audio/qcelp
W/AudioCapabilities(25467): Unsupported mime audio/evrc
W/VideoCapabilities(25467): Unsupported mime video/wvc1
W/VideoCapabilities(25467): Unsupported mime video/x-ms-wmv
W/VideoCapabilities(25467): Unrecognized profile/level 32768/2 for video/mp4v-es
W/VideoCapabilities(25467): Unsupported mime video/wvc1
W/VideoCapabilities(25467): Unsupported mime video/x-ms-wmv
W/VideoCapabilities(25467): Unsupported mime video/x-ms-wmv7
W/VideoCapabilities(25467): Unsupported mime video/x-ms-wmv8
W/VideoCapabilities(25467): Unsupported mime video/mp43
W/VideoCapabilities(25467): Unsupported mime video/sorenson
W/VideoCapabilities(25467): Unsupported mime video/mp4v-esdp

请帮我修正这个错误.谢谢

Please help me fix this error. Thanks

推荐答案

我通过处理 ssl Error 找到了类似问题的解决方案.基本上重写了 Webviewclient 对象中的函数 onReceivedSslError 并设置 handler.proceed(),消除了问题.

I found out the solution to similar problem by handling ssl Error .Basically overriding the function onReceivedSslError in the object of Webviewclient and setting the handler.proceed(), removed the issue .

      WebViewClient webClient = new WebViewClient() {
            // Override page so it's load on my view only
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap facIcon) {

                mLayoutProgress.setVisibility(View.VISIBLE);

            }

            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                    handler.proceed();
            }

            @Override
            public void onPageFinished(WebView view, String url) {

                mLayoutProgress.setVisibility(View.GONE);
            }
        };

这篇关于API 21 及更高版本中的 Android webview 加载失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆