Issue
I want to show an image in a webview which has been downloaded externally to ExternalStorageDirectory
. I am using the followng code to load the HTML as a string with the base URL set to be that of where the images are saved:
Article article = page.articles.get(0);
String mime = "text/html";
String encoding = "utf-8";
String base = "file:/" + Environment.getExternalStorageDirectory() + "/images_folder/";
Log.v("IMAGE", base);
webView = (WebView)rootView.findViewById(R.id.webView);
webView.setBackgroundColor(Color.TRANSPARENT);
webView.loadDataWithBaseURL(base, article.articleContent, mime, encoding, null);
This code works fine in the emulator but when I try it on a device (Nexus 7 Tablet) the image doesn't load. The image is definitely stored in the External Storage Directory as they can be found using a file explorer on the tablet. I imagine this has something to do with the Nexus 7 using emulated storage but I really don't know, the call Environment.getExternalStorageDirectory()
should point to the same directory every time.
The html String being brought in is very simple and looks like this:
<html><head></head><body><img src = 'test_download1.png'></img>This is the first Article for the first page in html</body></html>
Where test_download1.png
is a file stored in the External Storage directory.
Solution
To access SDCARD in nexus 7 you have to write a different code as your code will give access only to mnt/sdcard and not to actual path,where your image is saved.
code to access SDCARD in nexus 7
Answered By - Meenal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.