Issue
I have an entire folder that I would like to be in the R.raw folder so that it looks like this:
raw/thor/myfirstfile.jpg
raw/thor/mysecondfile.m4a
raw/thor/mythirdfile.json
raw/batman/myfirstfile.jpg
raw/batman/mysecondfile.m4a
raw/batman/mythirdfile.json
So that I could copy the folders to:
/externalSD/.../themes/thor/myfirstfile.jpg
/externalSD/.../themes/thor/mysecondfile.m4a
/externalSD/.../themes/thor/mythirdfile.json
/externalSD/.../themes/batman/myfirstfile.jpg
/externalSD/.../themes/batman/mysecondfile.m4a
/externalSD/.../themes/batman/mythirdfile.json
I cannot put the folder into R.assets because the project containing these assets is a library and I need to access the files from the application project.
It's also not an option to simple put all the files into the raw/assets/drawable/etc directory because the themes are essentially templates designed to search a directory on the SD card, the idea is that more themes can be downloaded.
At present my solution is packaging the folders into zip files as such:
raw/thor.zip
raw/batman.zip
Accessing them using:
InputStream fileStream = context.getResources().openRawResource(rawResource);
and then unzipping on the first run of the app onto the SD card - but it is painfully slow. It would (hopefully) be much quicker to simply copy a folder rather than unzip one.
My question is how can I copy an entire folder out of the R.raw resources?
Solution
I have an entire folder that I would like to be in the R.raw folder so that it looks like this
That is not supported. You cannot have subdirectories in res/raw/
. assets/
would work as an alternative to res/raw/
.
I cannot put the folder into R.assets because the project containing these assets is a library and I need to access the files from the application project.
Android library projects support assets nowadays, at least on Android Studio/Gradle for Android. I haven't tried them on Eclipse recently.
My question is how can I copy an entire folder out of the R.raw resources?
Since you cannot put a whole folder into res/raw/
, you cannot copy it out of there.
You are welcome to invent your own name-mangling algorithm (e.g., raw/theme___thor___myfirstfile.jpg
), so long as you stick to Java data member naming rules. You can then convert those filenames into relative paths when writing them out. You would need to iterate over the static data members of R.raw
using reflection to find out the names and their corresponding resource ID values.
But, I would suggest that you experiment with assets first, as it may work better than you expect. Or, if this library is purely for your own use (i.e., not for public distribution), perhaps switch to Android Studio and use product flavors instead of an application and a separate library.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.