I've searched but all I can find was making it into a website with the content as the image. Isn't there any direct way to load an image from the drawable folder in to a webview? Thanks in advance.
Asked
Active
Viewed 3,627 times
1
-
refer this answer this may help you to solve it.. [Android add image to webview from a drawable](http://stackoverflow.com/questions/4534043/android-add-image-to-webview-from-a-drawable) – Pragnesh Ghoda シ Jun 10 '14 at 10:09
-
You can't load image from drawables however why not you try loading from assets. – Ahmed Nawaz Jun 10 '14 at 10:11
-
Possible duplicate of [@Android display /res/viewable in WebView](http://stackoverflow.com/questions/2630829/android-display-res-viewable-in-webview) – rds Jun 23 '16 at 14:38
2 Answers
2
this link : Android add image to webview from a drawable
You can only do such a thing if our image is inside your /assets folder. Also, you must load your html with a baseUrl that's inside your assets folder.
You can use WebView.loadUrl() or WebView.loadDataWithBaseURL():
webView.loadUrl("file:///android_asset/file.html");
or
webView.loadDataWithBaseURL("file:///android_asset/", "", "text/html", "utf-8", null);
(file.jpg should be inside your assets folder)
Too , see this link:
how to load a picture from my resource in webview?
Android: how to retrieve an image from res/drawable and put it into WebView.loadUrl()
-
-
i think that not load directly "from android_res/drawable" - u should load from "android_asset" folder - just try it! – Saeid Jun 10 '14 at 11:24
2
I have found this answer from other post and it works for me by which we can load resource from drawable also.
web_object.loadDataWithBaseURL("file:///android_res/drawable/", "<img src='test.jpg' />", "text/html", "utf-8", null);

Manmohan Badaya
- 2,326
- 1
- 22
- 35
-
is this under the same folder? i mean the image and also the file html? – gumuruh Apr 05 '20 at 09:04