views:

211

answers:

2

I would like to add an HTML resource to my Android project with references to other resources (mainly drawables).

Where should I put it and how do I reference other resources from it?

Is there a particular way to pass the HTML resource to a WebView?

Thanks!

+3  A: 

The html file goes into the assets folder in root (as a sibling folder of res), as well as all the drawables. You can view it by doing something like

webView.loadUrl("file:///android_asset/filename.html");
EboMike
Thanks EboMike. And how do you reference other non-asset resources from the html file? Can't they be drawables?
hgpc
It's HTML, so you need to make it work so WebKit can render it. I assume that you can simply use <img src="image.jpg"> and place that image into the assets folder. If you have dynamic drawables, you could save them to the sdcard and reference them using "file:///sdcard/image.jpg". This is off the top of my head, the syntax may be incorrect.
EboMike
What about BitmapDrawables? I would like to avoid duplicating the files (one copy in res/drawables, the other in assets) to keep the file size of the app down.
hgpc
WebKit can't access your apps' resources. I wonder if you could do something exotic and create your own content provider, something like myapp://pictures/picture.jpg, which grabs resources and sends them back. But that's overkill. If you copy them to the SD card, they at least won't count against internal storage. There may be a better solution, but nothing obvious that comes to mind.Alternatively, you could try to create your images from bitmaps in the assets folder - just load them like you would load external image files and create Drawables out of them.
EboMike
A: 

If your file is on the SD card, this reference will work:

content://com.android.htmlfileprovider/sdcard/filename.jpg

gregm