1

I download the image and store in the local storage. I load this image from the html file from local storage.
<img src="file:///data/data/com.example/imagefiles/photo.jpg"/>

I load the html file from WebView. webView.loadUrl("file:///android_asset/show_download_image.html"); But the image didn't shown. I am sure the downloading image is successful. I want to know that is it possible to load the image from local storage into the html file or is there any way to load the image from local?

Thanks.

saschoar
  • 8,150
  • 5
  • 43
  • 46
user1156041
  • 2,155
  • 5
  • 24
  • 54
  • Do u want to load from sdcard. see this link [loading image in webview from sdcard ][1] [1]: http://stackoverflow.com/questions/5051364/load-the-image-saved-in-sdcard-in-webview – manivannan Aug 29 '13 at 04:42
  • You can store path of image in localStorage and displaying it. – Butani Vijay Aug 29 '13 at 04:54
  • Possible duplicate of [Android - local image in webview](http://stackoverflow.com/questions/6127696/android-local-image-in-webview) – rds Jun 09 '16 at 13:35

2 Answers2

3

Why not try to load image directly like this:

String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = "file://"+ base + "/photo.jpg";
String html = "<html><head></head><body><img src=\""+ imagePath + "\"></body></html>";
webView.loadDataWithBaseURL("", html, "text/html","utf-8", ""); 

Here the image is in sd card. You can change the code for keeping image in asset also.

Syamantak Basu
  • 905
  • 4
  • 10
  • 20
  • cos I use jquery and call the jquery functions in html. I want to load the image dynamically. so the keeping image in asset is not suitable. – user1156041 Aug 29 '13 at 04:56
  • But you said " I download the image and store in the local storage ". That's why I said you can download the image in either SD Card or Asset folder. – Syamantak Basu Aug 29 '13 at 05:17
  • I used `getFilesDir()` to get the local directory path. I don't know how to download into the asset folder. Could you pls give me some sample? – user1156041 Aug 29 '13 at 06:17
  • Sorry. I made a mistake. You cannot download an image to Asset folder. But can't there be a work around? You can download image in SD Card and then load this image to Html file(in Asset folder) from SD Card.. Is this possible? This is just a suggestion. You can also wait for some better answers.. – Syamantak Basu Aug 29 '13 at 07:15
1

check your webview javaScriptEnabled is true?

   WebView.getSettings().setJavaScriptEnabled(true);
T_V
  • 17,440
  • 6
  • 36
  • 48