Issue
I want to add a bunch of HTML files to my assets directory and determine at runtime how many there are and what their paths (or URLs) are.
How can I get a list of files in my assets directory?
How can I form path strings or URLs to read each one individually?
Solution
How can I get a list of files in my assets directory?
Call list()
on an AssetManager
to get a list of assets packaged in your app. You can get an AssetManager
by calling getAssets()
on a Context
.
Note that these are not files on the device. They are files on your development machine; they are merely assets in the app.
How can I form path strings or URLs to read each one individually?
That depends on what you mean by "read each one".
If you want to read the HTML in manually, call open()
on the AssetManager
, passing in the relative path to the asset.
IOW, for a file on your development machine in app/src/main/assets/hi/there.html
, you would call open("hi/there.html")
).
If you want to display the HTML in a WebView
, use file:///android_asset/hi/there.html
with loadUrl()
on the WebView
, for an asset located at the relative path hi/there.html
.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.