打开支付网站时的WebView显示空白页 - 棒棒堂 [英] WebView Shows blank page when opening payment sites - Lollipop
问题描述
我现在面临的问题加载URL到的WebView它总是展示的空白页,我看不到任何错误在我的LogCat中。它的工作原理罚款低于5.0 [棒棒堂]设备,只在棒棒堂的设备出现的错误。我试过很多解决方案present在计算器但他们没有工作。
下面是最终的code,我结束了。
网站我想负荷为: https://netbanking.hdfcbank.com/netbanking/一>
任何帮助,将AP preciated非常感谢。
进口android.annotation.TargetApi;
进口android.app.Activity;
进口android.app.AlertDialog;
进口android.app.ProgressDialog;
进口android.content.DialogInterface;
进口android.net.http.SslError;
进口android.os.Build;
进口android.os.Bundle;
进口android.util.Log;
进口android.webkit.CookieManager;
进口android.webkit.SslErrorHandler;
进口android.webkit.WebSettings;
进口android.webkit.WebView;
进口android.webkit.WebViewClient;
进口android.widget.Toast;/ **
*创建者谢蒂在2015年4月18日。
* /
公共类WebPageTest延伸活动{ web视图的WebView; / **当第一次创建活动调用。 * /
@TargetApi(Build.VERSION_ codeS.LOLLIPOP)
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_web_page);
字符串URL = getIntent()getStringExtra(URL)。
web视图=(的WebView)findViewById(R.id.webview);
WebSettings设置= webView.getSettings();
settings.setJavaScriptEnabled(真); // webView.clearSsl preferences();
settings.setDomStorageEnabled(真);
如果(Build.VERSION.SDK_INT> = Build.VERSION_ codeS.LOLLIPOP){
。webView.getSettings()setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
webView.enableSlowWholeDocumentDraw();
}
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptThirdPartyCookies(web视图,真);
webView.setWebViewClient(新SSLTolerentWebViewClient(){
@覆盖
公共无效onReceivedSslError(最终的WebView视图,最终SslErrorHandler处理器,SslError错误){
Log.d(检查,onReceivedSslError);
AlertDialog.Builder建设者=新AlertDialog.Builder(WebPageTest.this);
AlertDialog alertDialog = builder.create();
字符串消息=证书错误。
开关(error.getPrimaryError()){
案例SslError.SSL_UNTRUSTED:
消息=证书颁发机构不受信任。
打破;
案例SslError.SSL_EXPIRED:
消息=该证书已过期。
打破;
案例SslError.SSL_IDMISMATCH:
消息=该证书主机名不匹配。
打破;
案例SslError.SSL_NOTYETVALID:
消息=该证书尚未生效。
打破;
}
消息+ =是否继续?
alertDialog.setTitle(SSL证书错误);
alertDialog.setMessage(消息);
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE,OK,新DialogInterface.OnClickListener(){
@覆盖
公共无效的onClick(DialogInterface对话,诠释它){
Log.d(检查,OK按钮pressed);
//忽略SSL证书错误
handler.proceed();
}
});
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE,取消,新DialogInterface.OnClickListener(){
@覆盖
公共无效的onClick(DialogInterface对话,诠释它){
Log.d(检查,按钮来取消pressed);
handler.cancel();
}
});
alertDialog.show();
}
});
webView.loadUrl(URL);
}
}
管理摸不着头脑。关于您的网站和一个我一直在挣扎的事情是,他们试图占据全屏的高度。我的WebView(我想你也一样)有layout_height =WRAP_CONTENT,虽然它有,因为相对布局内定位适当的高度,瞄准SDK时21 WebView中被报告高度为0到页面产生的所有元素崩溃0高度为好。所有你需要做的是改变layout_height web视图来match_parent。
临提示为开发者提供的WebView呈现问题挣扎。使用的WebView远程调试 https://developer.chrome.com/devtools/docs/remote-debugging
它可以与这样的问题时节省了大量的时间。
I'm facing problem Loading URL to a WebView it always show's blank page, and I can't see any error in my LogCat. It works fine on below 5.0 [Lollipop] devices, The error occurs only in Lollipop devices. I tried many solutions present in StackOverflow but none of them worked. Below is the final Code that i ended up with. Site I'm trying to Load is : https://netbanking.hdfcbank.com/netbanking/ Any Help would be appreciated thanks a lot.
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);
}
}
Managed to figure this out. The thing about your site and the one I was struggling with is that they are trying to occupy full screen height. My webview (and I think yours as well) had layout_height="wrap_content", and although it had proper height because of positioning inside relative layout, when targeting sdk 21 webview was reporting 0 height to the page resulting all its elements collapse to 0 height as well. All you need to do is to change layout_height of the webview to match_parent.
Pro tip for developers struggling with webview rendering problems. Use webview remote debugging https://developer.chrome.com/devtools/docs/remote-debugging It can save a lot of time when dealing with problems like this.
这篇关于打开支付网站时的WebView显示空白页 - 棒棒堂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!