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

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

Related

Downloadable files in my application

I created a project which uses Fragments, and in one of them I want to add some clickable icons that will allow to download a file (one per icon).
I have the files stored on my computer.
I suppose that they have to be copied into my application.
How I can implement this in the code?
I hope that this picture can explain what I want to do.
will allow to download a file and they have to be copied into my application don't match: If the files are already on the device (once your app is installed), what is the sense of downloading those files again?
Therefore, either provide your files inside your app or use a file server and download them.
If you decide to provide the files in your app, this will increase the installation time.
But it would not require an internet connection to download the files again.
So, simply put your files in the raw or in the assets folder and that's all.
Then simply access your files from that folder.
If the folder isn't already found in your project, simply create it and drop your files in it.

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

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.

Why can't we read an sqlite file from /raw or /assets?

I have an sqlite database I want to distribute with my application. It's about 3mb. If I understand correctly, I can't directly open it if it resides in my app's /raw or /assets folder, right? We need to first copy it out of that directly as in:
Get the SQLite path within the Assets Folder
So my app will consume twice the disk space as it normally would? I don't understand why it's necessary to have the database file be in a particular folder?
Thanks
So my app will consume twice the disk space as it normally would?
Yes. Technically, probably more, as your database is compressed inside the APK file.
I don't understand why it's necessary to have the database file be in a particular folder?
It is not necessary for the database file to be in a particular folder. However, assets/ is a folder on your development machine; it is a part of the APK file on the device. Same goes for everything in res/raw/.
BTW, I recommend SQLiteAssetHelper for copying the database out of assets/.

Categories

Resources