Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 534
Mridang Agarwalla Avatar asked Sep 11 '12 12:09

Mridang Agarwalla


People also ask

Why is my WebView not working?

You might often face issues in updating the chrome and Android System Webview. To fix this problem, you can reboot your device, check your internet connection, stop auto-updating all apps, clear Google Playstore cache, and storage, leave the beta testing program, and manually update Android WebView app from Playstore.

How do I add a website to my Android WebView?

Modify src/MainActivity. java file to add WebView code. Run the application and choose a running android device and install the application on it and verify the results. Following is the content of the modified main activity file src/MainActivity.

What is alternative of WebView in android?

Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.

How do I open a link in WebView?

Within the shouldOverrideUrlLoading() method simply get the URL from the request and pass into the Intent. See the full example.


2 Answers

Enable DOM Storage APIs

wbvBrowser.setDomStorageEnabled(true);
like image 191
ozmank Avatar answered Oct 02 '22 07:10

ozmank


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

    <uses-permission android:name="android.permission.INTERNET" /> 
like image 20
Mark Avatar answered Oct 02 '22 06:10

Mark