0

There are more questions like this but no one solved my problem:

I am trying to load a string into a webView. All works fine always when I have internet connection. When there is no internet connection, the content is not displayed. I do this:

WebView wb = (WebView) findViewById(R.id.webView1);
wb.loadData("Lorem ipsum dolor sit amet",  "text/html", "utf-8");

These are the permissions I request in Manifest.xml file:

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

As I said, it works fine with internet connection, and does not load the content when there is no internet connection. What I need to do to get the webView work without internet connection. I am targeting Android 3.2 with a 2.1 as minimal version

1 Answer 1

1

Edit:

You could create your html or txt file in your assets directory and load that file:

webView.loadUrl("file:///android_asset/filename.html");

Source

Try loadDataWithBaseURL:

String html = "<html><body>Hello, World!</body></html>";
String mime = "text/html";
String encoding = "utf-8";

WebView myWebView = (WebView)this.findViewById(R.id.myWebView);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadDataWithBaseURL(null, html, mime, encoding, null);

Code from: https://stackoverflow.com/a/4543485/480415

2
  • Same thing, works with internet connection, does not work without connection Jan 9, 2013 at 19:10
  • I added something else to try in my post above
    – RyanG
    Jan 9, 2013 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.