WebView在打开付款网站时显示空白页 - 棒棒糖

use*_*008 2 android webview

我遇到问题将URL加载到WebView它总是显示空白页面,我在LogCat中看不到任何错误.它在5.0 [Lollipop]设备下工作正常,只在Lollipop设备中出现错误.我在StackOverflow中尝试了很多解决方案但没有一个能够工作.以下是我最终的最终代码.我正在尝试加载的网站是:https://netbanking.hdfcbank.com/netbanking/ 非常感谢任何帮助.

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.webkit.CookieManager;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

/**
 * Created by shetty on 4/18/2015.
 */
public class WebPageTest extends Activity {

    WebView webView;

    /** Called when the activity is first created. */
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_page);
        String url = getIntent().getStringExtra("url");
        webView = (WebView) findViewById(R.id.webview);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);

       // webView.clearSslPreferences();
        settings.setDomStorageEnabled(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
            webView.enableSlowWholeDocumentDraw();
        }
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptThirdPartyCookies(webView,true);
        webView.setWebViewClient(new SSLTolerentWebViewClient() {
            @Override
            public void onReceivedSslError(final WebView view, final SslErrorHandler handler, SslError error) {
                Log.d("CHECK", "onReceivedSslError");
                AlertDialog.Builder builder = new AlertDialog.Builder(WebPageTest.this);
                AlertDialog alertDialog = builder.create();
                String message = "Certificate error.";
                switch (error.getPrimaryError()) {
                    case SslError.SSL_UNTRUSTED:
                        message = "The certificate authority is not trusted.";
                        break;
                    case SslError.SSL_EXPIRED:
                        message = "The certificate has expired.";
                        break;
                    case SslError.SSL_IDMISMATCH:
                        message = "The certificate Hostname mismatch.";
                        break;
                    case SslError.SSL_NOTYETVALID:
                        message = "The certificate is not yet valid.";
                        break;
                }
                message += " Do you want to continue anyway?";
                alertDialog.setTitle("SSL Certificate Error");
                alertDialog.setMessage(message);
                alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Log.d("CHECK", "Button ok pressed");
                        // Ignore SSL certificate errors
                        handler.proceed();
                    }
                });
                alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Log.d("CHECK", "Button cancel pressed");
                        handler.cancel();
                    }
                });
                alertDialog.show();
            }
        });
        webView.loadUrl(url);
    }
}
Run Code Online (Sandbox Code Playgroud)

use*_*058 7

管理好解决这个问题.关于你的网站和我正在努力解决的问题是他们试图占据全屏高度.我的webview(我认为你也是)有layout_height ="wrap_content",虽然它因为相对布局内部的定位而具有适当的高度,但是当定位sdk 21时webview报告了0页面的高度,导致其所有元素都折叠到0高度同样.您需要做的就是将webview的layout_height更改为match_parent.

开发人员在使用webview呈现问题时遇到的专业提示.使用webview远程调试https://developer.chrome.com/devtools/docs/remote-debugging 处理这类问题可以节省大量时间.