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.
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.
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/.
How to write to .txt file in assets folder.
How to get path assets folder ?
You can't. The assets folder is read-only at runtime.
Pick a different location to save your data, see Data Storage for more information.
The path of assets folder is file:///android_asset But this is read-only.
The assets folder is like folders res, src, gen, etc. These are all useful to provide different files as input to build system to generate APK file for your app.
All these are read-only while your app is running. At run-time you can only write to SD card.
I hope you understand my answer.
Not possible,
Better you choose internal storage to save your txt file. Internal Storage. Hope this will help you to understand.
No you can't do this, because of if you read and write both at runtime then everything could be change and application will behave unexpected which could be harmful or may be crashed. i suggest you to use internal memory, sqlite and app SharedPreferences etc.
i have a file in the asset folder, and when i press a button in my program i have to move that file in a sub-folder(run-time). Can it be done?
i have to do this:
assets/file.txt -> assets/aaa/file.txt
No your assets are compiled into your apk file. Consider storing a persistent preference marking whatever you are trying to do instead.
No, you can't do it. You can't write anything inside the assets folder programmatically. Better option is to use internal storage. You can use Files Folder in the internal storage. See getFilesDir() in the docs.
Reason: Once you have an .apk file it is read only, so you can't add, delete or modify in it,
Alternate:
though you can use the sqlite DB for the purpose... where you can save file in hierarchy using blob type and you can modify it through queries...
I have a database which contains Image paths. I have access to the existing Images by these database paths.
I also need a folder containing Images which are writeable to modify the images.
Besides "assets" files are only readable, so I can't change them. Therefore the "assets" folder doesn't work for me.
What is the best file storage in this case?
My solution was to save images in assets and then copy the folder in an internal storage, but it takes a large amount of memory.
The best way is to save the files in internal or external android device.