I’m developing an application which has some assets bundled with it – they are mostly web pages with associated graphics, css etc which I’ll display in a custom WebView. I’m trying to work out how to serve up different assets to different devices without massive duplication.
I’d like to replicate the res folder, but for assets. For example:
assets/html/page1.html references assets/html/example_pic.png but I want to serve up a different example_pic.png depending on screen density or screen size.
Ideally I’d like to have something like assets_hdpi/html/example_pic.png and assets_mdpi/html/example_pic.png
Is there an elegant way of achieving this? Can I somehow utilise the /res/ folder management to the same end result by putting the example_pic.png in to /res/drawable_hdpi etc and then somehow pointing the webpage to the drawable?
A possible workaround:
Prepare a ‘subpath’ named string for the different resolutions you want to address, e.g.:
res/values-hdpi/subpath.xml:<string name=”subpath”>hdpi</string>res/values-ldpi/subpath.xml:<string name=”subpath”>ldpi</string>Prepare corresponding subpaths in your asset folder, e.g.:
assets/hdpi,assets/ldpiand store your assets there.Finally, use
getResources.getString(R.string.subpath)to get the best asset subpath.