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.
Related
In my flutter project, I want to download some files from a url and save particularly in a folder named data. I have added Read and Write permission in AndroidManifest.xml file. I have also tried some solutions like the below link-
flutter - How to download asset when apps launched and used it
But none of them was effective for me. some of the solutions let me save the file in SD card but I only need to save the file in my data folder and read data from the file whenever I need.
Here's the picture where I exactly want to save my file-
So, I need a proper solution to download the file from the url and save it to this particular directory.
https://pub.dev/packages/download_assets if you don't want to add assets at time of build try this package it download asset from server and store it in assets
I have code for creating an internal file, there is random algorithem that create the data stored in it and i want any app to have the same file with the same binary data in it.
so i need to make the file on my desktop and add it to internal files some how.
my question is what do you think is the best way to do it.
i thought to locate it in my project, read it, and write it to internal files.
the problem is, i dont know where to locate my file in android studio so that it will be included in the external files and then where to read it from.
thanks. =]
hope i made myself clear.
Put it in src/main/assets/.
You can then access your file with AssetManager and do whatever you want with it.
From the Android Developers website:
main/assets/
This is empty. You can use it to store raw asset files. Files that you
save here are compiled into an .apk file as-is, and the original
filename is preserved. You can navigate this directory in the same way
as a typical file system using URIs and read files as a stream of
bytes using the AssetManager. For example, this is a good location for
textures and game data.
You need to move that into the assets folder. From there you can refer to the file.
So I have some files I want my Android App to access, read and write.
I want to store it internally. Where can I put these files in my Java Project so they are accessible or can this not be done?
There are three ways to achieve this, and according to your requirements select the approch
on SDCARD
This is the normal SDCARD/in-build SDCARD in newer smart phones. you need to create specific folder structure and put your files there, here you can do file read and write both
but this in insecure because accessible to all the application
on Internal Storage
This is given as Applicaiton specific storage where you can create the file and do the operation, this is most secure way to do it, but this is generated run time so you can not push the files directly, you can put your files in RAW or ASSETS and copy that here
RAW and ASSETS
This is in the code structure only and only read access is given to this folder, you can not change this file run time.
if you select any one of this approach then simple goggling will show you the sample code.
You can read or write files in the path of your internal storage as
data/data/package_name/files . I had already answered a similar question you can check it out.
I need to store and read objects in Android, these Object must be available until they are manually deleted through the app.
Since I cannot use the assets folder for this,
How could I store objects in an hide folder to access them in future?
Well, you can keep them in your app specific directory in SD card. If you want the content inside your directory should not be scanned by mediascanner (so that they will not appear in Gallery etc), you need to keep a ".nomedia" file in that directory.
for example, create a directory called "mytestapp" in sdcard, and keep a ".nomedia" file there, along with the files you want to store
I have the following situation:
I have files under raw directory. I use them to load them to textview.
I want user to load files from web to be used the same way.
Is it possible? Or do I need to load them to SD?
If so - on the SD - how do I prevent reading\copy of these files (in raw directory it is not reachable).
You can load files to the SD card, to internal storage, an SQLite data base, or as a Preferences object. This is discussed here, including security aspects.
What you cannot do is dynamically add to the resources or assets folder that ships with your app.