I am developing an app that needs to refer to data in a number of XML files. There are a lot ( ~40) XML files required by the app.
The file have names like “AbnormalFlags-v1.0.xml” and I current have them located in
res/raw/v2/AbnormalFlags-v1.0.xml
res/raw/v2/ActualDeliveryPlace-v1.0.xml
res/raw/v2/AddressType-v1.0.xml … …
A number of questions
- Is this the best place to locate these files ?
- The filenames seem to be a problem, will that cause issues
-
Because I have to dynamically determine which file to use I use the:
xmlFile = getApplicationContext().getResources().getIdentifier(xmlFileId,"raw","com.apps4health.refpack");
This does not find the resource file, where am I going wrong ?
Given the format of the file names I would suggest you to save them in the
assetsfolder. Create a folder namedassetsinside theresfolder and put there the XML files.The code below shows how to open files in the
assetsdirectory:AssetManager is responsible to open files saved in the
res/assetsfolder. You just call theopen()method passing the file name as argument.