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
Related
There's a snippet of code in the Android sample's FacePreview class that boggles me:
File classifierFile = Loader.extractResource(getClass(),
"/org/bytedeco/javacv/facepreview/haarcascade_frontalface_alt.xml",
context.getCacheDir(), "classifier", ".xml");
I know I should change the names before haarcascade_frontalface_alt.xml to match my project name, but I can't figure out where to actually put the XML file in my project structure.
I did read somewhere that I have to put the xml file in the same folder as the FacePreview class... so does that mean I have to put it in src/main/java/<package_name>?
Edit: That doesn't work either. Do I have to download and cache it in the Activity?
it goes in src/main/resources/org/bytedeco/javacv/facepreview/haarcascade_frontalface_alt.xml
assuming gradle does the right thing
I have a file that I open and parse and some of the categories can be modified. Im wondering how I can update the original Xml file with the new values.
I assume that the XML file is a normal sequential file. If so, you could try to update just one tag, but it would be easier and safer just to rewrite the entire file.
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.
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);