我有一个Webview,我正在尝试加载this url
但是webview是空白的,我在清单中添加了互联网权限,试图在同一个网页浏览中加载google.com并且加载正常。
尝试在手机浏览器(Chrome)中加载相同的网址并加载
这是我的代码:
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webviewmain);
mWebView.setWebViewClient(new WebClient());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(url);
}
private class WebClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
}
}
logcat的:
I/chromium: [INFO:CONSOLE(1)] "Angular is running in the development mode. Call enableProdMode() to enable the production mode.", source: https://www.xfinityprepaid.net/CustomerActivation/vendor.23a90aa3d57e711f4e5c.bundle.js (1)
I/chromium: [INFO:CONSOLE(1)] "ERROR", source: https://www.xfinityprepaid.net/CustomerActivation/vendor.23a90aa3d57e711f4e5c.bundle.js (1)file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:186;Function:ASN1_get_object
D/libc-netbsd: getaddrinfo: adservice.google.co.in get result from proxy gai_error = 0
D/libc-netbsd: getaddrinfo: match.adsrvr.org get result from proxy gai_error = 0
D/OpenSSLLib: OpensslErr:Module:12(116:176); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:186;Function:ASN1_get_object
D/OpenSSLLib: OpensslErr:Module:12(116:176); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:186;Function:ASN1_get_object
D/libc-netbsd: getaddrinfo: www.facebook.com get result from proxy gai_error = 0
D/OpenSSLLib: OpensslErr:Module:12(116:176); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:186;Function:ASN1_get_object
D/OpenSSLLib: OpensslErr:Module:12(116:176); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:186;Function:ASN1_get_object
D/libc-netbsd: [getaddrinfo]: mtk hostname=www.xfinityprepaid.net; servname=(null); netid=0; mark=0
解决这个问题的任何方法?
答案 0 :(得分:4)
我有类似的问题。经过长时间的研究,我添加了许多代码,它开始工作。这不是正确的答案,但我的Angular网站开始着手添加此代码。检查并告诉我它是否有用。
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAllowContentAccess(true);
webView.loadUrl(url);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setDomStorageEnabled(true);
webView.clearView();
webView.setHorizontalScrollBarEnabled(false);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
webView.getSettings().setDatabasePath("/data/data/" + this.getPackageName() + "/databases/");
}
webView.setVerticalScrollBarEnabled(false);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setPluginState(WebSettings.PluginState.OFF);
webView.setScrollbarFadingEnabled(false);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webView.setInitialScale(1);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.loadUrl(request.getUrl().toString());
}
return false;
}
});