WebView不会加载某些图像

时间:2015-10-06 11:28:20

标签: android image webview

我有以下WebView配置,而不是在Lollipop 5.0及更高版本中为某些图像充电。通常降低负载(在4.0,4.1和2.3中测试)。 通过检查显示任何错误日志。

if(!url.equals("")) {

    webView = (WebView) findViewById(R.id.wvProduct);

    webView.getSettings().setJavaScriptEnabled(true);
    webView.clearCache(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
    webView.setWebChromeClient(new WebChromeClient());

    webView.loadUrl(url);

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {
            view.loadUrl(urlNewString);
            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) {
            if(LoadingDialog.instanceProgressDialog().isShowing()) {
                LoadingDialog.dismissDialog();
            }
        }
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            if(LoadingDialog.instanceProgressDialog().isShowing()) {
                LoadingDialog.dismissDialog();
            }
            Log.e(ConstantsAdAlive.ERROR, "****Error: " + description + " code: " + errorCode);
        }
    });

} else {

    new AlertDialog.Builder(this)
        .setTitle(R.string.INIT_ERROR)
        .setMessage(R.string.webview_error)
        .setCancelable(false)
        .setPositiveButton(
            android.R.string.ok,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    WebViewActivity.super.onBackPressed();
                }
            })
        .create()
        .show();
}

if (android.os.Build.VERSION.SDK_INT < 16) {
    webView.setBackgroundColor(0x00000000);
} else {
    webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
}

if (android.os.Build.VERSION.SDK_INT <= 15) {
    // android 4.1.2 - sony, resfresh WebView
    webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
}

0 个答案:

没有答案