My Android app uses HTML files included as assets and displays these inside WebViews.
The HTML files must reference other files created dynamically by my application. The dynamic content cannot be included statically in /assets nor should it be fetched online every time the HTML is loaded inside the WebView. Instead, the app must fetch/generate the online content once and store it for future reference when an HTML file is displayed.
I have found two solutions up to now, and neither is satisfactory:
-
Place all content inside /assets statically. Then I can reference it inside the HTML files as follows:
TAG src=”image.gif” END_TAG
-
Store the dynamic content in the sdcard and reference it from HTML as follows:
TAG src=”/sdcard/app/image.gif” END_TAG
The first solution does not allow for dynamic content as (I think that) I cannot write to /assets dynamically. The second solution works but it is not great. First, I hard-encode references to /sdcard which I do not feel comfortable with. Second, the device has to have an SD card installed and mounted.
Overall, I would prefer the be able to store the dynamic content inside the app’s on-device memory and then reference it from HTML. Is this reasonable/good-practice/possible?
Note that the “dynamic content” is not so dynamic — it is updated very rarely and I want to have it cached.
Thanks,
Correct.
Possible? Yes. Create a
ContentProviderto serve your content, then usecontent://URLs, and it should work.