1

How to store html files in Drawable in resource and access them. I want html files inside the application i don't want to link them from localhost or from sdcard.

Rahul
  • 73
  • 10

3 Answers3

2

For that you have to create assets folder in you main directory and paste html file in it and load that file with following code :

WebView wv = (WebView) findViewById(R.id.YOURID);
wv.loadUrl("file:///android_asset/*.html");
1

Instead copy your html file in assets directory and use it as follows

WebView webView = (WebView) findViewById(R.id.YourWebView);
webView.loadUrl("file:///android_asset/your.html");

You can not add html files in drawable folders because drawable directory is used for different purpose as follows from the docs.

Though usually not visible to the application, Drawables may take a variety of forms:

Bitmap: the simplest Drawable, a PNG or JPEG image.

Nine Patch: an extension to the PNG format allows it to specify information about how to stretch it and place things inside of it.

Shape: contains simple drawing commands instead of a raw bitmap, allowing it to resize better in some cases.

Layers: a compound drawable, which draws multiple underlying drawables on top of each other.

States: a compound drawable that selects one of a set of drawables based on its state. Levels: a compound drawable that selects one of a set of drawables based on its level. Scale: a compound drawable with a single child drawable, whose overall size is modified based on the current level.

Nikhil
  • 3,711
  • 8
  • 32
  • 43
0

You can't load html files from drawable folders. For that you have to keep your html files in assets folder, and from there you can load these files in your webview.

Use the following code to do so.

WebView mWebView = null;
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("file:///android_asset/new.html");

To create assets folder right click on app folder and then navigate to Folder menu. From that select Assets folder . It will create your assets folder in proper place.

Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84