I am trying to create a application in that i need to access the xml file which is in different application.I have tried using packagemanager but i am able to get the resource Ids of the xml file. How can i get the access of the complete xml from my app?
Simple !
1) save theme file to the local path (in phone)
2) store that path where your theme file stored ( try to manage with xml because its light weight so will be lighter in mobiles)
3) import that file from the location (fetched from xml file)
Enjoy XMLing and Android !
Related
I have a desktop application that produces resource / data files for my android app. These are XML text files that store instances of my custom data class. These objects are serialized using the Simple XML Serialization library. In my android app, I'd like to instantiate objects from this XML serialization class.
I like to add these xml files to Android Studio so they are included in the APK on device install and are placed, for example, in the private app directory "files", to which getFilesDir() is mapped. I can't find a way to do that.
If I add these xml files to the Android XML resource folder, I need to use Android's XML resource parser, and can not use the Simple XML library.
Any tips? I feel I made a wrong design choice seeing how restrictive the resource bundling is.
Thanks, Kind regards,
Harmen
As per CommonsWare's comment: the solution was adding it to the raw resource folder, then you can access it using:
InputStream xmlExerciseInputStream = getResources().openRawResource(R.raw.myresource);
MyClass myClass = serializer.read(MyClass.class, xmlExerciseInputStream);
I'm developing a test class that have to check if there are all the resources. It's a specification mandatory that i access to the resources by file name (png's).
I know there's the possibility of loading as a resource, but I cannot load resources. I'm developing a test app. How I could access the file file.png in res/drawable named ?
new FileOutputStream("/res/drawable/xxx.png");
It is recommended to read Resources Overview from Android docs,but if your problem is only about accessing resources,read Accessing Resources.So you can do what you want.
Summery,there is some ways to access resources that depends on situations,for example when you know name of resource or you know it's ID.And also it depends that where you want to access resources.
In your case I guess that you want to access a drawable in your code,if it is true,you can do like this:
R.drawable.xxx
For example if name of your .png file is myimage and you have to set it in ImageView with name im do this:
ImageView im = ...;
im.setImageResource(R.drawable.myimage);
Edit:
If you have to get an InputStream form a file in resources,you should consider creating a raw folder inside res directory and put your file in it and then call getResources().openRawResource(resourceName) from your Activity or widget.For example :
InputStream ins = getResources().openRawResource(R.raw.test);
Here your file that is in raw folder is for example test.png.
You can see more details here:
Using files as raw resources in Android
Android: Loading files from the Assets and Raw folders
stackoverflow
stackoverflow
stackoverflow
Finally if you want to create an output file from your resource,get an InputStream from it and write it's content to an OutputStream,you can see a good example here.
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 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.
Is there a way to programatically get the path to the databases/files an application uses instead of hardcoding "data/data/mypackage.com/database.db" ?
For files: Context.getFileStreamPath() (alternatively, Context.getFilesDir() for the whole directory).
For databases: Context.getDatabasePath()