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.
Related
I am writing a file encryption app.
I set up the file(s) browse code using the default storage directory.
This works great, I wrote the code to be able to encrypt multiple files as well as directories.
Directories simply get copied, and the files within are encrypted into a new directory.
The problem is now after some research I have found that I need to utilize the storage access framework to be able to select files from external sd cards, and any other storage system the user may have.
My question is, is there a way to select multiple files and folders simultaneously through activities in the saf? Is there a workaround for this? I found an activity that is able to select multiple files, and I found one that allowed me to select a single directory.
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.
I am really new to android devices, we have got an app that needs to read a *.cfg file from the same place as the apk. So the question is:
1) When i attach my mobile-phone to the computer, can i put it from the explorer? If yes, how?
2) Is there a mechanism in Android, that looks for some kind of include directories
when opening a Program?
It would be great if you could give me a hint.
You'd want to drop the *.cfg files into the assets/ folder. Then the app will have access to those raw *.cfg files during runtime.
From Managing Projects
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.
Well, I tried to search in google and SO, but didn't find much mainly because I am not sure what should be my search word. So, if anybody thinks this question is too generic and should be searched first, please help me providing some useful link.
What I want is, to have two buttons in my App which should download sample.csv and sample.php (I want to attach this file inside my App) file and save it to user directory, preferably in "download" folder or somewhere user can access easily.
I found this page by searching but here they demonstrates saving File on Internal Storage in App's folder only. Now I am confused whether this App's folder is accessible by browsing or not (I can't find my app's folder in my Samsung Note 2).
Another question pops up in my mind is, whether I have to read those sample files and create new file to save, or I can simply put a link and download the sample files I provided (more like HTML link)? Or may be I can just upload those sample files in my web server as zipped and give a link to dload?
Apology for my long email, but I am confused where to start.
Thanks,
You can not access your app's internal directory. However, what you can do is to use InputOutputStream to copy your file from the internal directory to your desired folder, and then delete the file from the app's directory. Try searching for copying files and you'll find multiple links.
I am creating an app that could potentially be used in multiple educational establishments across a variety of courses with tutors who will want to be able to update some of the information within the app themselves on an ad hoc basis. I originally thought that the best way to do this would be to have the application download a new strings.xml file to the res/values folder, though I have read that you cannot update this folder/file whilst the app is packaged and running. I think a good work around for this would be to be able to save another strings.xml file elsewhere
My questions are:
Is this at all possible?
Where would I go about saving the strings.xml so that it is not
packaged when I export the app?
note: The file will not be called string.xml so there will be no confusion etc. with the actual strings.xml.
There is no "rule" of where you should put the file (minus, of couse system and other private folders you can't access). However, the logical and most common place to put a non-packaged resource that your app downloads would either be in your own applications data folder (located on the internal storage of the device) or on the external storage of the device (SD card).
To write your file to the internal storage you will need to use the context's openFileOutput(..) method. This stores the file within your apps private data directory. Use openFileInput(..) to read your stored file
To write to external storage you will need to add the WRITE_EXTERNAL_STORAGE permission to your manifest. After doing that, you can use FileOutputStream to write your files data when downloading. InputStream for reading (look up which input stream type would be most suitable)
Obviously, the examples I'm giving aren't fully detailed or have code but they will guide you in the right direction for storing files on your device.
Files under the res folder are used by the compiler to autogenerate the R class that contains the ids of the strings,layouts,drawables etc...
Of course you can download a custom resource from your server and stored it in the SD as #dymmeh points. And is the most reasonable way of to achieve modification of literals but be aware, you will not be able to use the #string/string_id in your layout's xml and you will have to parse the downloaded file yourself.