views:

307

answers:

1

I'm trying to display the content of a html file with the loadDataWithBaseURL() method in android.

I just have a String that contains the Html file data in one String called source and I then pass this to the method.

for e.g

String source; //contain html tags with images
View.loadDataWithBaseURl(null,source,"text/html","UTF-8","about:blank");

The data displayed in view is fine. My problem is if my html file contains any images then I couldn't displayed it? how can I do that?

A: 

you can do it, if the images in the source use relative locations for the src then you need to set the baseUrl to the "base" of where the images would be located. for example, if you were loading google's home page from the source, it would look like this:

View.loadDataWithBaseURI("http://google.com",source,"text/html","UTF-8","about:blank");

That tells the webview where the images will be loaded from.

As a side note, I do not think "file://" URIs works in the web view, for security reasons.

Ryan Conrad
I use a file URI to load images into a webview from the internal memory and it works fine
Janusz