Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView loadDataWithBaseURL not working for files in app folder

In my local storage I have the following folder /data/data/com.test.testapp/files/1/images

and the following file exists. /data/data/com.test.testapp/files/1/images/f.png

These were stored/retrieved using context.getApplicationContext().getFilesDir()

In my HTML I have "<img src="f.png" />"

I can get TextView working with html/images using an ImageGetter, which effectively returns a drawable from:

Drawable.createFromPath(targetFile.getAbsolutePath());

Where the targetFile is as described above ends up being (/data/data/com.test.testapp/files/1/images/f.png)

However, when I try to use WebViewer as follows (I've pasted in the string for ease):

String url = "file:///data/data/com.test.testapp/files/1";
webViewer.loadDataWithBaseURL(url, content, "text/html", "utf-8", null);

Where content ends up with the same text as my TextView.

All I get is an image placeholder, i.e. it didn't find it.

like image 614
Neil Walker Avatar asked Nov 22 '25 18:11

Neil Walker


1 Answers

OMG! ;)

How petty are those people at Google!

All I had to do was append a slash to the url so the base url:

file:///data/data/com.test.testapp/files/1

When changed to

file:///data/data/com.test.testapp/files/1/

Works.

like image 102
Neil Walker Avatar answered Nov 24 '25 09:11

Neil Walker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!