Android systems files ,<resource> and <assets> in particular - android

I am trying to write a code that lets me programmatically switch a file from one of my resources folders to my assets folder. I have tried the usual file.renameTo method that has worked so very well for me in the past....but with android it seems to do nothing...

The assets and res folders are part of the structure of the .apk file. This isn't something that can be changed by the application on the phone. You can create a folder structure in the phone's file system, but that will need to be accessed from your app by the file access api, not as assets or resource identifiers.

Related

Where should I store local files for a WebView

Lets say I want to store a JavaScript file in my app for an Android WebView to use. Where should I put this file? My first though would be somewhere in the assets folder, but I am not too sure.
Check the following link and explanations:
http://www.41post.com/3985/programming/android-loading-files-from-the-assets-and-raw-folders
The Assets folder is an 'appendix' directory. The R class does not
generate IDs for the files placed there, so its less compatible with
some Android classes and methods. Also, it’s much slower to access a
file inside it, since you will need to get a handle to it based on a
String. There is also a 1MB size limit for files placed inside the
Assets folder, however some operations are more easily done by placing
files in this folder, like copying a database file to the system’s
memory. There’s no (easy) way to create an Android XML reference to
files inside the Assets folder.
There is also a raw folder you can even use that, but:
it’s important to highlight the main differences between the raw
folder and the Assets folder. Since raw is a subfolder of Resources
(res), Android will automatically generate an ID for any file located
inside it. This ID is then stored an the R class that will act as a
reference to a file, meaning it can be easily accessed from other
Android classes and methods and even in Android XML files.
Using the
automatically generated ID is the fastest way to have access to a file
in Android.
For completing the answer, you can easily use file:///android_asset/
Have a look at this question:
Android WebView Javascript from assets

How to Update Assets Folder in Android Dynamically from Web Service?

In assets folder in my Android project, i have .dat and .xml files. They must be updated periodically. I don't want to update them by myself, there is a web service that i will store new .dat and .xml files as .json objects. How may i make the application update assets folder by itself?
Thanks.
As Siddharth Lele mentions in the comments, you cannot update assets/ at runtime, except by upgrading the app to one that contains a newer assets/.
You can, however, download your .dat and .xml files to internal storage. Then, when you need to use one of these files, check internal storage first. If there is a file there, use it. If not, fall back to the copy in assets/.

Do Apps carry XML?(XML file that was created during development)

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); ).

Android load and modify file

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).

Add some files to my android app folder

I am planning my android app with some files in the app folder, but i didn't figure out how to add files to my project. I don't want to use the files as resources because the user should be able to save or download more files in the same folder and i just wanted to add the basic set of files.
Can anyone help me? :/
I don't want to use the files as resources because the user should be able to save or download more files in the same folder and i just wanted to add the basic set of files.
There is no direct means of doing this. If you package your files as assets (in assets/) or as raw resources, you are welcome to copy them out of your APK into internal storage on first run of your app.

Categories

Resources