i am creating an app where i unzip the files and load it to SD card but instead i wish to load them to the assets folder on the project. How to do this can any one help me with this
You cannot write into your Apps Asstes Folder.
Use data/ on SD Card or for small things the SharedPreferences instead.
Related
I have a question, I want to ask about reading data from files to construct setting for application.I want to download new files from the server to replace the files in the asset folder, but the files in asset folder doesnt allowed me to replace them, So I want to know is there any other way to do this ?
The assets folder in Android, are readonly, you can't add or edit files. So, if you want to use internal data files and replace them with a download, you have to set another directory, such as Internal Storage or External Storage.
Following are my understanding of them, and want to make sure it's correct.
Assets folder is a directory that I can place files so app can use.
This is immutable folder.
Internal storage is a directory you are given when your app is installed.
You can mutate files under this directory.
If I maintain a read-write sqlite database, I will probably make it here under internal storage.
If I want to provide an initial database though, I would have to place it under the assets folder, and copy it when app is first run.
Yes, your understanding is correct. The difference between the Assets folder and the Internal Storage folder is that the Assets folder can't be changed at runtime. So the usage of internal storage and assets folder is as follows-
1) When one has fixed content like fonts,images,styles,string values,etc. put it into the assets folder.
2) If based on the programme the values must change based on the situation then save those values in the Internal Storage.
Yes you're right. The difference is that assets folder is read only folder. You can put your files there and use them in your app but if you need to change or modify them, you should copy them from assets to internal then do your works, so if you have static texts or fonts or files that needs nochange you can put them in assets folder but if you have database files you should copy ithem to internal.
I want to add some HTML files in my program that can be update later.
I want to add these files in assets folder but I can't rewrite files when downloaded.(eclipse)
The assets folder is inside of you package - obviously you can't edit that.
Download such updates to your applications data directory. You'd then have to check in code if there is a file in the data directory, and if not use the one in assets.
Suppose I store various images in raw folder. However, my own code first learns of the file names at runtime. (It reads a text configuration file at startup.) Is it possible to then search "raw" folder in my android app and if found, load image from raw into imageview?
Okay, thanks to Mario I got on track to doing some research. These 5 SO's explain everything:
Android images in /assets or res/raw
Reading assets or raw or resource files as a File object in Android
How to reference a File in raw folder in Android
Check for file existence in androids assets folder?
Difference between /res and /assets directories
My project have multiple files in SD card. But when I install apk file on phone it does not work.
Please tell me how to attach those files with apk.
Your sdcard files cannot become the part of APK file, if you want those files to attach to your apk, insert them into asset folder or raw folder.
EDIT:
If you put your file in raw directory then:
com.your.package:raw/yourFile
Like this:
int resourceId = context.getResources().getIdentifier("com.your.package:raw/somefile.txt");
File f = new File(context.getResources().openRawResource(resourceId));
And here's someone doing it with the assets folder:
Android Assets with sub folders
InputStream is = getAssets().open("subfolder/somefile.txt");
Create a sqlite database and store the path of whatever files you want to store on the sdcard. Also you can store them in assets folder depending upon the type of file but it is not a good practice as many say.
You could store the supporting files on a web server and have the application download the files to the sdcard on first run. This is what many games do. Google Play also offers free storage of files for applications.
Here is the Google blog post on large APK's
http://android-developers.blogspot.fr/2012/03/android-apps-break-50mb-barrier.html