我現在面臨的問題加載URL到的WebView總是顯示的空白頁,我看不到任何錯誤,我logcat中。它在5.0 [Lollipop]設備以下工作正常,僅在棒棒糖設備中出現錯誤。我嘗試了很多存在於StackOverflow中的解決方案,但都沒有工作。 下面是我最終的代碼。 網站我試圖負載:https://netbanking.hdfcbank.com/netbanking/ 任何幫助將感謝理解了很多。的WebView顯示空白頁 - 棒棒堂
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);
}
}
感謝哥們,無論如何解決了這個問題,使用一個示例GutHub項目。但這是我的問題的確切解決方案。感謝您的幫助 ! – user3458008