8

I'm using a WebView to open some files saved to the app. Is there a way to link to the app's directory where files saved at runtime would be, in a similar way that file:///android_asset/ does? By link I mean loadUrl( *path* ) and also in the HTML markup of the file being opened <img src="*path*" />

As oppose to using an absolute path like file:///data/data/PACKAGENAME/files/

cottonBallPaws
  • 21,220
  • 37
  • 123
  • 171

2 Answers2

7

Use this for files on the SD card:

content://com.android.htmlfileprovider

Use this for files in your assets directory:

file:///android_asset

Also, if you want to have all your references in your web view use that base directory set the baseUrl field like this, where "baseUrl" is the root directory as I mentioned above:

webview.loadDataWithBaseURL(
        baseUrl, htmlText, "text/html", "UTF-8", null);
Padma Kumar
  • 19,893
  • 17
  • 73
  • 130
gregm
  • 12,019
  • 7
  • 56
  • 78
  • 1
    What is content://com.android.htmlfileprovider ? How can i use this if my images are in: mnt/sdcard/mypackage/images/picture.png – Adam Varhegyi Aug 01 '12 at 08:19
3

from android 2.1, they've added the

"file:///sdcard/..."

support for files on the sdcard

so :

loadUrl("file:///sdcard/path/to/my/file.html");
Padma Kumar
  • 19,893
  • 17
  • 73
  • 130
guian
  • 31
  • 1