I want to use a webpage to display my content because that will utilize the built in zoom and scroll feature in android. I know that I want to have the webpage on the sdcard to allow for not having internet access, but I don't know how to call it from the res/raw/ folder. Can I get some help? Thanks
Asked
Active
Viewed 4,519 times
4 Answers
7
There is one condition that we cannot use assets
folder. What if we want to have a WebView load resource from library project. assets
folder is not supported but res/raw
does.
As long as I know, the following work fine starting from API 8:
webView.loadUrl("file:///android_res/raw/webPage.html");

Yeung
- 2,202
- 2
- 27
- 50
-
Why minus me? I am telling the fact!! Reference asset in library project is possible but it need [special handle](http://stackoverflow.com/questions/6346889/how-to-reference-an-asset-in-a-library-project) !!!! – Yeung Jul 29 '14 at 03:06
-
Thanks, for me this worked. using res/raw/ and res/raw-us/ only this worked! thanks! – cV2 Jul 29 '15 at 14:09
-
Be aware that a workaround is needed when the _aplication id_ is different in a _buildVariant_, like for example [with a suffix](http://stackoverflow.com/questions/26777566/file-under-res-raw-not-accessible-in-debug-buildvariant). – Sebastian Apr 24 '17 at 16:36
2
Put the webpage in the assets
folder instead. Then when you want to load it, use this line of code:
webView.loadUrl("file:///android_asset/myWebPage.html");

Jason Robinson
- 31,005
- 19
- 77
- 131
0
First get String from Drawable Folder, see following link to get contetnts of a file from raw folder:
http://www.41post.com/3985/programming/android-loading-files-from-the-assets-and-raw-folders
and Then you can use WebView's loadData method to load html contents in webview.
Other method is to load html file by:
mWebView.loadUrl("file:///android_asset/myfile.html");

jeet
- 29,001
- 6
- 52
- 53
0
You can set an html file from the assets folder like this
WebView wv;
wv = (WebView) findViewById(R.id.webView1);
wv.loadUrl("file:///android_asset/aboutcertified.html");

blessanm86
- 31,439
- 14
- 68
- 79
-
1Would I need to make a WebView in the main.xml for this method? I ask that because of the use of findViewById – Easy Apr 20 '12 at 20:11
-
You can put the web view either in the main.xml file or just include to the layout programatically using java. – blessanm86 Apr 21 '12 at 00:54