简体   繁体   中英

Why doesn't Android's WebView load some URLs?

My WebView doesn't show some URLs especially if it has the leading www. part missing. http://google.com doesn't load but http://www.google.com loads just fine. I don't get any exceptions or messages in the logcat so it seems rather hard to find out what's going on behind the scenes. Here's the snippet that actually displays my WebView .

WebView wbvBrowser = new WebView(this.objContext);
wbvBrowser.getSettings().setBuiltInZoomControls(true);
wbvBrowser.getSettings().setJavaScriptEnabled(true);
wbvBrowser.loadUrl("http://google.com");

Would any of you know what's causing this issue? I'm baffled.

Thanks.

启用DOM存储API

wbvBrowser.setDomStorageEnabled(true);

Make sure the app has permission to access the Internet. Add the following to AndroidManifest.xml:

    <uses-permission android:name="android.permission.INTERNET" /> 

try this...

wbvBrowser.setWebViewClient(new Callback());
private class Callback extends WebViewClient{  //HERE IS THE MAIN CHANGE. 

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return (false);
    }

}

This worked for me: Add an 's' to the http. Make it https

wbvBrowser.loadUrl("https://google.com");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM