user1156041
user1156041

Reputation: 2195

Android: load image from local storage to webview

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.

Upvotes: 1

Views: 10762

Answers (2)

T_V
T_V

Reputation: 17580

check your webview javaScriptEnabled is true?

   WebView.getSettings().setJavaScriptEnabled(true);

Upvotes: 1

Syamantak Basu
Syamantak Basu

Reputation: 935

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.

Upvotes: 3

Related Questions