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.
3 Answers
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");

- 166
- 9
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.

- 3,711
- 8
- 32
- 43
-
@Rahul Yes it will work. Thanks for credits It Motivate us to help :) – Nikhil Oct 01 '16 at 10:00
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.

- 5,669
- 9
- 46
- 84
-
-
yes you have to create assets folder under res directory of your project. – Vivek Mishra Oct 01 '16 at 09:31
-
sorry by mistake I described the wrong place for creating assets folder. I have updated it in my answer – Vivek Mishra Oct 01 '16 at 09:54
-
As of 2020, the assets folder has to be created beside /res to work, not inside res/. – PravyNandas Sep 10 '20 at 03:13