Where should I store files for my app? My app is a home automation app for advanced users that will require them to upload images (floor plans, custom dashboards, etc) and xml configuration files to the phone. Where should I store them?
That depends on how portable you want the files. Do you want the user to user them elsewhere (SDCard)? Do you want to back them up (Server)? Should the user never really care where they are (Device)? This really depends on how you want to use your files (or how the user may want to use your files).
Further, another thing to take into consideration it the file size. If they are huge, then the SDCard is the obvious choice.
Related
I am writing a specific use-case camera app that targets Android 11. When I hit record I would like to create a new directory somewhere (with a name based on the timestamp etc) that contains the resulting video as well as a whole heap of other custom YAML/JSON/CSV files that also get written during the recording process (belongs logically to the "output" of the recording).
I would like all of the generated files to survive an app uninstall/reinstall as I do not want to risk users losing everything they've ever recorded if they uninstall the app. How do I do this with the new scoped storage changes etc in Android 11?
Looking at the overview here, I can see that:
App-specific files, App preferences and Database are clearly not suitable as amongst other things these files do not survive an uninstall
Documents and other files uses the Storage Access Framework, but this is not suitable because it requires a system file picker every time you want to write something. This would disrupt the flow of recording/user experience, and no camera app works like that.
Datasets/BlobStoreManager (here) also is not appropriate for my use case.
MediaStore API looks like it should be the one, but it can't seem to do what I want in terms of producing a whole directory of outputs, including custom YAML/JSON/CSV text files, that all belong together. My aim is that the user at all times can simply go to the file explorer, navigate to the appropriate folder, and just copy out the folder(s) with the recordings to their computer or whatever, to save/view the data. Even MediaStore.Files does not seem to guarantee you can actually do that if your app is using scoped storage.
The only option that seems to be left is using MANAGE_EXTERNAL_STORAGE and putting the data wherever I want in the home directory, but that seems like a bit of an extreme permission to be asking for just in order to be able to save some text files along with my produced videos. Also, that permission is Android 11 specific. If I want to support older Android versions, what would I need to do?
What is my best choice here? Is there an option I've missed?
but this is not suitable because it requires a system file picker every time you want to write something
No.
Use ACTION_OPEN_DOCUMENT_TREE to let the user pick a document tree. In there, you can create your own sub-tree and put your own documents into that sub-tree. You do not need the "system file picker" for anything beyond the initial ACTION_OPEN_DOCUMENT_TREE request itself. And the resulting documents will survive an uninstall.
You can create your own directory in a public directory like DCIM, Pictures, Music or Movies with classic File methods.
I am writing a small medical app as means of trying out my newly learned Android skills. I want to be able to read a text file from a specific folder on the device (not the SD card) where the user can put some medical information (when the app starts upp) without having the user need to pick the file destination, but I am not sure how to implement it. I may also want to write to the file.
The file may change frequently. The truth is, I need to read from a directory with a variable number of subdirectories, each with 4 files in them. It is those files I need to read and then display, but for the sake of simplicity I limited the question to just reading the file. It seems like this would be a file which would be in "Internal Storage/Android/data/com.me.myapp/medical_information", but I am not sure how convenient that would be for the user to constantly have to find the app among all of the app folders, and then navigate to the folder. Where would be the best place to put this folder/file, and how would go about writing/reading from it?
It is preferrable that answers be written in Kotlin, but not essential.
My company has three different Android apps that provide functionality for sales reps. We opted to separate the apps into "modules" because not all reps need all the modules. Up to now we have been using a JSON file in a directory on the SD card of the devices to set some configuration data for the apps. However, it appears that with Android 10 and beyond this will no longer be possible.
Currently we use getExternalStorageDirectory() to access the SDCARD and then open a file inside a directory our app creates.
Since we want the file access to not be something the sales reps have any control over we want it to happen transparently. However it does not seem this will be possible going forward.
Will using a custom FileProvider or even a DocumentsProvider be a way to continue to share data between our apps?
Another question, although not as important, is, can we change the default location of the DB files our app creates as we do now in earlier versions of Android?
Thanks
Rich
I'm wanting to include some wallpapers and custom icons with my next application update. What's the best way to go about that in Android? I've been doing some searching but I haven't seen anything satisfactory.
Thanks.
Just change the icon and the background and update the app. Or do you mean something else?
I know if your app moves/copies the files to the user's SD card then the media scanner should pick it up and include in the Gallery app. Which can then be used as a wallpaper. But as for using them directly from your app, I'm not sure.
Might be good to not include them in the app directly, but allow the user to choose to download them from within your app (if you have a server or external site you can host them on). That would keep the size of your app small, and allow you to download them directly to the user's SD card.
I have a general doubt about how to design Android apps that use a lot of MP3 (or other audio) files. My problem is that I do not know what is the best way/location to store such files.
I know that these options are available:
Store them on a remote server and fetch via gprs/wifi on demand (like, on a button click)
Store them locally inside the app (taking care they do not exceed the max size)
Store them locally on the sdcard (a user could delete them)
Store them both remote and locally
Could you tell me what is the best way to do? Also, if you store these files locally, do you download them after a user installs an app or you use some other method?
For example, my last app had approx 400MB of MP3 files and I was in a deep doubt where to store them. I chose remote web server, but I am not sure that was the right choice.
Thanks in advance
I'm interested in how you convince people to download 400MB of Music-files. You should compress them.
I would store them on the SDcard. If the user deletes them -> His problem (you could give him a message). But streaming them is a bad idea because if the user has no connection, he can't hear anything.
Downloading the files after the user installed the App (like the "Need for Speed Shift"-App) would be an option, too. In this case, you would save them on the SDcard, too.