I would know if is it possible upgrade a XML file in an Android application.
I have a XML file in /raw/ , i want implement a function (like "check update") that controls if the XML is it older than another file in a server, the XML file contain a version number such as Version="1.0".
In this case, if the XML version of the file in the server is it > than 1.0 i want download this file and replace the XML file in /RAW/
How i can do this ?
You can't. What you can do however is copy the XML from res/raw in your app data folder at first launch, then work on this one, on which you have write access.
Related
I am using the below code to create a file in android as
File file = new File(getApplicationContext().getFilesDir(), "content.txt");
I want to open the file in my phone. I went to the path
Local storage/Android/data/<my package>/files/
However, I cannot see the file. My Android version is 5.0.1. What is happen? One more thing, Do you think the above way is a good way to save file? What is common path to save a file in Android? Thanks
The file locates in /data/data/[your package]/files,it's app private directory.
It's a good way or not depends on the purpose of your file.
if you want your file visable only to you(the app developer),the folder is right
if the file can be visable to others and the file is large,then you can put it to sdcard folder
if you want the file stay even if your app being removed,you shouldn't put it in this folder.Because when an app removed,the all data in /data/data/[package name]/ will be deleted also.
You find in:
/data/data/[your package name]/files/
I have an Game App, and i'm using a lot of XML's I was wondering if those XML's are carried by the APK? will those XML files will be installed together with the application itself? Because there is a part of my App where I use DOM Parser to update a XML file and the updated XML file will have its content permanently unless you update it again
Any XML file in the res or asset folder will be shipped with your application inside the APK (be careful though as the XML files in the res folder might get compressed, so be sure to open them using context.getResources().getXml(R.xml.identifier);).
As for the second part of your question, any file packed in the APK cannot be modified at runtime. But you can copy the XML files from your app into a folder, either public on the SDCard or in your apps private directory (for example context.getDir("mydir", Context.MODE_PRIVATE); ).
I have a short question about writing to a file in android. I am writing a game where I use a xml file to save some data about the level stats. Now I have seen that if I save this xml file in AssetManager it is not possible to change it (only permissions to read files).
Now because I can only modify files which are in the filesystem of android (using openFileInput and openFileOutput to work with it) I wonder where I have to save my (already existing) xml file in my eclipse project so that I can use openFileInput to load it and change it via code.
Do I have to make a new folder? E.g. project_path/files/myxml.xml.
Is it even possible to load a file which was created (outside the AssetManager folder) before installing the .apk to target?
If it is possible does anybody have some example code?
I hope you understand my question.
There is no such place. Installation of android apps does not include an automatic step that would copy your content from apk to the internal folder (and your application does not reside in the folder either).
You will have to create your XML file in code, possibly checking for its existence before each access (or using some other marker).
I have an android application I am developing in Java.
I need it to load a text file so it can read what is in the text file and get values from it.
However, everything I have read so far has been directing me to use resources and package it up with the application.
However this means if I want to change the text file, I have to reinstall the application, which is not what I want.
I need to end up with the .apk file and the .txt file in the same folder on my android phone so I can change the .txt file and the app reads in the text file in its directory.
Can anyone help?
No, you do not want to end up with the .apk and the .txt file in the same folder.
You want to end up with the .txt in some place that's always the same and that you know about.
You can deploy the initial .txt via the ressources (aka: package it and copy it to the sd for example) and later download a new version (or copy something to the device via usb).
Then inside your app check if the file exists and open it with standard Java. There's plenty of source around for that.
I want to update the content of a file on my res/raw folder called dbschema.xml, using a newer version of dbschema.xml that is somewhere on the phone (for exemple, at data/data//dbschema.xml)
I've already done the part to check if the new file exists, and i want now to copy it to raw.
Do you have any idea?
Thanks.
It's not possible, you can't modify the content of those files since they are inside the installation package. You could instead copy the file to the private directory of your app, read it from there and update when needed.