Android webview loading fail in API 21 and above

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-18 17:08:41

问题


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

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


回答1:


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



回答2:


I had the same problem & I followed @DRY Believer's Answer, but when I uploaded the application to google Play, they rejected the application and said Your app is using an unsafe implementation of WebViewClient.onReceivedSslError

Instead, I found a way to correctly install my SSL certificate on the server, and that fixed the problem



来源:https://stackoverflow.com/questions/41631830/android-webview-loading-fail-in-api-21-and-above

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!