I'm coding an android app for parsing sms messages. I need different rules for different countries and idea is to define rules for my country and later open source project so other users can contribute with rules for their countries. XML format is the most convenient in my opinion for defining these rules.
So I have an app which reeds rules from XML file stored in res/raw and users will later be able to update that set of rules or download rules for some other country when those become available.
As I said I have put existing XML files in res/raw, but the problem is when users download new or changed set of rules application can not change or store files in resources (correct me if I'm wrong).
So I have two options now, and I don't like either one. I would like to hear your opinions on the matter.
a) I can keep XML files as local files, but then I must read in default rules from res/raw and copy them into file system on application installation, or keep track of two separate bunch of files. Is it possible to preinclude files on file system when installing an app?
b) I can keep XML code in database, but also copy it from files at install time. Or even worse code XML as String in class to insert it on install?
I apologize if question is too long or unclear, English is not my native language and this is my first question.
I'm not sure if i understood you right, but you could store the XML-file in the internal data storage of the application. --> http://developer.android.com/guide/topics/data/data-storage.html
If you want to attach a first Version of the XML-file on install, store it in the ressources first and copy it to the internal data storage after install. On updates of the XML file you can just overwrite this file in the internal data storage.
Hope i could help you, this is my first answer on stackoverflow. I'm sorry if i just told you things you already knew.
Related
My requirement is I need to modify client configuration information into one values/client_configuration.xml at runtime. I Google it, couldn't resolve issue. I don't want to keep in sharedPreference. Because this application already developed need to do some modification only. So are there any ways to change file?
please guide me.
Thanks
You cannot change any files that are included with the application as it's distributed. What you can do is copy an XML file from inside you assets folder, for example, to the internal storage and then use it from there. You can modify the file on local storage as necessary. Or use a sqlite database.
You didn't provide any context about what it is you really need to do, but it sounds like you don't have a full understanding of how apps utilise storage. I strongly suggest you read Storage Options sections of the Android documentation.
Consider an app with a set of data files (could be music or pictures or locations or indeed anything at all) embedded in the apk.
I now want to provide to the user additional data files , either to replace or add to the original data files - the user should be able to select which files to download and not have to reinstall the whole app.
So the question is it possible to do this non-programmatically - like by providing extra apk files for the app but which only contain single data files?
This is a good use case. A simple idea could be, ask the user to check for updates, you download a XML file which defines your updates. Parse this XML file and show what the user needs to download. Then you download and save it to desired locations. Always version the XML file so that you know if updates are avialble or not!
I am creating an app that could potentially be used in multiple educational establishments across a variety of courses with tutors who will want to be able to update some of the information within the app themselves on an ad hoc basis. I originally thought that the best way to do this would be to have the application download a new strings.xml file to the res/values folder, though I have read that you cannot update this folder/file whilst the app is packaged and running. I think a good work around for this would be to be able to save another strings.xml file elsewhere
My questions are:
Is this at all possible?
Where would I go about saving the strings.xml so that it is not
packaged when I export the app?
note: The file will not be called string.xml so there will be no confusion etc. with the actual strings.xml.
There is no "rule" of where you should put the file (minus, of couse system and other private folders you can't access). However, the logical and most common place to put a non-packaged resource that your app downloads would either be in your own applications data folder (located on the internal storage of the device) or on the external storage of the device (SD card).
To write your file to the internal storage you will need to use the context's openFileOutput(..) method. This stores the file within your apps private data directory. Use openFileInput(..) to read your stored file
To write to external storage you will need to add the WRITE_EXTERNAL_STORAGE permission to your manifest. After doing that, you can use FileOutputStream to write your files data when downloading. InputStream for reading (look up which input stream type would be most suitable)
Obviously, the examples I'm giving aren't fully detailed or have code but they will guide you in the right direction for storing files on your device.
Files under the res folder are used by the compiler to autogenerate the R class that contains the ids of the strings,layouts,drawables etc...
Of course you can download a custom resource from your server and stored it in the SD as #dymmeh points. And is the most reasonable way of to achieve modification of literals but be aware, you will not be able to use the #string/string_id in your layout's xml and you will have to parse the downloaded file yourself.
I have created an android app that calculates the numerical values of word, and gives you a list of other words with the same numerical value. The way I have been doing it, is storring the words and value in a .properties file. Ie. A line from a .proprties file called "myWords" will have something like: 61=you, then I just use a get() method to call it,
ie. String myString = ResourseBundle.get("myWords").get("61"); would return the string "you". Is there a better way to do this? My guess is that this is not the proper use of a .properties file, and I was wondering if there was another way to do this correctly. I want to include the file in assets folder of the app, and from my limited understanding of sqlite, you can create a file within android, but you can't just include a file in the assets folder, and then read it. So that said, is there some other type of file that I should use, or was I wrong about sqlite, or is the .properties file being used correctly?
SQLite is your best bet and is the best way to handle your data on an Android phone, that is why Google bundled it on Android in the first place, to avoid people the pain of dealing with files.
If you follow this Tutorial they will show you how to create your database in your computer and then load it up on your "assets" folder and access it from your Android application.
Hope that helps!
You can use a csv file, read it from the assets folder each time the app starts or only once after installation and then store the values in a database.
Take a look at my answer here on how to read the files included in your app (you would use a csv file instead of a libray, but it's still reading files): Hosting an executable within Android application
Edit: here's another example to read from the assets folder: Image uploaded from the android app space seems corrupted
You can try out database option. Here is an interesting tutorial on how to pre-populate a database and then ship it out in the APK.
Hi fellow android developers!
I am developing an application where I have XML files that contain my data. When doing edits in these data, I save the data to the XML files, thus these must be editable.
This I would be able to achieve using the local storage for my application with the openFileOutput method of my Context.
But how would I go around shipping my program with these datafiles already there, with some pre-filled data?
I can see the option of shipping with some XML files in my res/xml or res/raw, duplicate them to the local data storage, but then I would be unable to remove the files in my resources, and this would take up too much storage.
Please tell me what you would do in this case?
You can not include editable files with your application.
So you will have to write them to the local file system some way. Either by downloading them or including them as raw resources via openRawResource().