I'm beginner of android.
And I get a problem.
Can I get the file under the folder I create in res/raw?
For example: res/raw/img/img123.jpg
Can I get the id or use the file img123.jpg?
if yes,how can i do that?
Please read this:
http://developer.android.com/guide/topics/resources/drawable-resource.html
Instead of accessing it as a raw resource, try creating a res/drawable/img123.jpg to easily access it using
getResources().getDrawable(R.drawable.img123);
Related
Is is possible to add new values in List Preference in for example pref_data_sync.xml from code in Android app. If yes, how to get the date from this file?
Thanks for all replies.
No, you cannot modify a xml preferences file. You cannot modify a resource android file by code.
But if you want to append it using code you can do something like this: https://stackoverflow.com/a/5437844/3482000
I'm trying to read an xml file which I plan to include as part of my mobile application. I've created a folder called "XML" and added a file called "test.xml". The files build action is set to content. When I run the app it crashes on trying to find the file. Here is the code I'm using:
_path = "XML/test.xml";
doc = new XmlDocument();
doc.Load(_path);
Here is the error I get:
System.IO.DirectoryNotFoundException has been thrown.
Could not find a part of the path "/XML/test.xml"
Do I need to register the directory/folder somehow? Thanks for any advice, I'm sure I've just missed something simple...
Do you mean that you'd created XML directory inside of your project?
If you want to include XML to your APK - one of the best ways will be to create /res/xml/file.xml and read it inside application with Resources class.
Please have a look at this thread - maybe you'll find it helpful. Open XML file from res/xml in Android
Good luck
I'm storing app data in a few XML files. Should I put these XML files in the 'res' folder? Is there anything special I need to do besides just using something like:
XmlPullParser xpp = getResources().getXml(R.xml.myXMLfile);
Thanks
I would suggest to store these file in the assets folder. Use the following code to read file form the assets folder:
getResources().getAssets().open(fileName);
No, nothing, as long as these are completely static in nature.
If it is an app data & if you feel to have lightweight app then try to store in the internal memory ,make use of it & get benefited.
Sorry, this seems like such an obvious question, but I just can't find an answer in the docs...
I have my own XML doc (not Android related) that I need to pull and parse at run time.
Where do I store it and what's the best way to retrieve it? Do I just read it as a text document into an XML parser? Or does Android come prepared to hand me back a parsed XML object from a well formed xml?
TIA
Put it in a xml folder in res.
You can put it in assets folder of your project.
For parsing you can use openXmlResourceParser(filename) method of AssetsManager class
XmlResourceParser parser = getResources().getAssets().openXmlResourceParser (String fileName);
Best way is to put your xml in assets folder and read xml from assets.
Read xml from assets
i m working on a project in which i have to store and read some list elements in xml format i did the prasing part by creating file in res/xml and and using getResources().getXml(R.xml.SAMPLEFILE); it works well.. problem arise when i go for file creation..i m unable to find tutorial which lets u creat or open(if already created) xml in res/xml..
http://www.anddev.org/write_a_simple_xml_file_in_the_sd_card_using_xmlserializer-t8350.html
You cannot add anything to your res folder during runtime. If you want the xml to be stored there you'll have to add it in when you compile. If you need it to be dynamic then you'll have to store the xml file in a different place.
One option you have is private internal storage for your application. Check out this page
for an overview of how to save to and read from this internal storage.