I created a simple html file that loads some images from my local hard-drive (ubuntu).
It is enough to put
<img src=/home/user/directory/image.jpg></img>
Now I need to know if it is the same when Html5 is displayed on a tablet like Android or iOS, or Html5 is used in offline app.
I mean, if html5 can load an image from the device’s filesystem just like on my computer, without localStorage or sessionStorage.
On Android, it can be done even though it looks a bit tricky at first. Say you have defined a WebView in your layout.xml, which you want to fill with an html file shipped with your application, which in turn should import a png also shipped with your application.
The trick is to put the html file into
res/rawand the png intoassets.Example.
Say you have
hello.htmlwhich should includebuongiorno.png.Within your project, say
MyProject, placebuongiorno.pngintoMyProject/assets.The
hello.htmlgoes intoMyProject/res/raw(because we want to avoid having it ‘optimised’ by the android resource compiler), and could look like this:In your java code, you would put this code:
where
getResourceAsString()is defined as follows: