Reputation: 107
I have to show some HTML content in WebView which has both images from URL's over the internet and images from the local phone cache. The src tag of the img has values like the following:
file:///data/data/com.Domain.MyApp/cache/example.jpg
but WebView renders no image. I am sure that the path is correct and that file exists. What could be the problem and how can I solve it?
Upvotes: 3
Views: 2175
Reputation: 107
Set src
attributes of img
tags like in this example:
/data/data/com.Domain.MyApp/cache/example.jpg
Save the HTML content as an HTML file into the same folder with the images (cache directory in the current problem).
Finally load the html file like this:
mDescriptionWeb.loadUrl("file://" + this.getCacheDir() + "/" + "current.html");
Upvotes: 4
Reputation: 12768
I think cache
directory is not really a safe place to store things. Have you already considered the option to use getExternalStorageDirectory()
?
My app download the contextual help from internet, save all files in getExternalStorageDirectory() + "/help"
and open it from a WebView
without any problem.
Look at:
http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory%28%29
Give it a try...
Another option is to use Assets, look at http://developer.android.com/reference/android/content/res/AssetManager.html
Upvotes: 1