4

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!

hpique
  • 119,096
  • 131
  • 338
  • 476
  • The following question might give a more clear picture. http://stackoverflow.com/questions/1892753/how-to-show-static-html-page-in-android-emulator – Thomas Feb 16 '13 at 06:55

2 Answers2

13

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
  • 76,846
  • 14
  • 164
  • 167
  • 1
    Thanks EboMike. And how do you reference other non-asset resources from the html file? Can't they be drawables? – hpique Jul 21 '10 at 00:53
  • It's HTML, so you need to make it work so WebKit can render it. I assume that you can simply use 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 Jul 21 '10 at 01:02
  • 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. – hpique Jul 21 '10 at 01:05
  • 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 Jul 21 '10 at 01:09
  • Having it in assets also means it can't be in a library project as you would have to copy these assets into all app projects that use the library or use another library that uses the library. – Marcus Wolschon Jan 04 '12 at 13:52
0

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

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

gregm
  • 12,019
  • 7
  • 56
  • 78