Android: how to store resources that may be updated at runtime - android

What is the best way to store sound files (ogg) that are distributed with the app and updated at runtime?
I am developing an app that includes a default set of sounds as resources (res/raw/*.ogg). These work fine for the defaults but I want the user to be able to update the set of sounds with recorded sounds and downloads from the Internet. The problem is that the resources are read-only and, I think, assets are also read-only. I don't know how to include files in the project so they can be updated at runtime.
I can have the defaults as resources and files added at runtime on internal storage or SD Card, but I would prefer to have all the files in one place with a single interface for accessing them. Is there a way to include files in the project so they are written to internal storage or SD Card when the app is installed? Or is there a better place to put the files?

Put your files in /asset directory when packaging the .apk file. At runtime copy those files in application's internal storage /data/data/<application_package_name>/files (If files are not to much sized, It useful when device has no external storage included). Also update the files in same location..

Related

Bundle app with files located in internal storage directory instead of assets directory?

I am building an app which will contain media files that are bundled with the application.
Users will also be able to download additional media files at runtime.
I want to store the downloaded files in the application's internal storage directory.
Is it possible to "bundle" the initial files in such a way that it is also stored in the internal storage directory, or will I need to place them in assets, and thus have two different ways of accessing my media files?
Is it possible to "bundle" the initial files in such a way that it is also stored in the internal storage directory
If you are looking to have them be placed there automatically, then no, there is no option for this.
will I need to place them in assets, and thus have two different ways of accessing my media files?
You are welcome to copy the assets to the filesystem yourself (see AssetManager). You would treat the filesystem as the "system of record" and only copy things there if needed (e.g., first run of the app, after user does "Clear Data").

Protect my Android app's files from "cleaners" and "optimizer" apps?

A rare but reoccurring problem reported with one of my apps is that "all my files were deleted" (files referring to project files generated from said app, save files essentially).
The culprit ends up being those "optimizer" apps that clean "unwanted" files from your Android device. Because my app generates custom-file-extension files, maybe they're not recognized and deleted?
Regardless, I know of the .nomedia file, a file used to tell media players to ignore a directory when scanning for media. Is there a similar file to "protect" directories from automated modification/deletion? Maybe even something placed in the Android Manifest?
Save the files in the internal storage that your app is assigned to by the system. No other apps can access it as it is private to your app. If you save files in a public directory, any app can access that.
File dir = context.getFilesDir()
To get your app's storage 'partition'

How to access files which is stored in custom folder of internal storage using external app?

I have a zip file. I am unzipping it to internal storage. When unzipping each file, I am keeping the same folder structure. After unzipping all levels, I want to display the files using appropriate third party apps like adobe reader etc.
I can unzipping and creating files with same folder structure. But the problem is the files could not be displayed through external app, because of permission. I couldn't set WORLD_READABLE PERMISSION, because the files are storing in custom folders. I applied setReadable also. But no hope.
How can I show files, or how to get permission to files?
Any help would be appreciated..
Thanks
Jomia
Use FileProvider to serve up the files from your app's internal storage using a ContentProvider.
Or, put the files on external storage, instead of internal storage.

How do android developers choose directories to store their files

I want to store some files when I develop an android app. There are two ways to store the files: use internal directory or use external directory.
As far as I am concerned, if the developers don't want their users or other apps can get access to the files, the file should be stored in internal directories. And if the developers do want the files can be accessed by users or other apps, the file would be stored in external directory.
And here is my question:
when choosing to store files in external directories, should I classify the types of files and store them in different directories like 'Download', 'Movies', 'Picture' ... or make a single directory for my app and store all my files in that directory.
As an android phone user, I don't like the second solution. So I am wondering why so many apps (such as Evernote) choose to create a directory in my external directory, '/sdcard'.
I would say if the files are of interest for the user or other applications store it in a type specific directory.
The second approach, one directory per app, can be used for files that are kind of private to the application. Many devices have more space available in external storage than in internal storage. An application may therefore choose to put its files there even if they are internal in nature.

Start Android app with files on sdcard or somewhere in the filesystem

I making an application with phonegap/cordova where I need to keep a lot of files up to date. Some files (mainly images) will need to be erased in time, and some new ones will get downloaded. The thing is, in Android, to manipulate those files, it seems I need to have them on the sdcard; so I copy the files the app starts with from my assets folder to the sdcard. It just seems like a waste of memory space.
Do you know if is there anyway I can start with the app having those files the app starts with already inside the sdcard? or at least somewhere I can delete them later?
Thank you.
Files that are delivered to the device as part of your APK will be stored in a form that cannot be modified by your application (other than by updating to a new version of the apk).
If you copy the files out of the APK into the private internal storage area or the external storage area, those copies can be modified, but the originals inside the apk will remain.
The most efficient solution may be to not put these files in your apk, but have your app instead download them separately on the first run, using whatever mechanism you wanted to use to change them in the future.
(Some people object to this feeling that such files are less secure against unauthorized use, but as the contents of an .apk are trivial to extract this is not a strong argument. Needing to maintain a server to download from is a slightly more substantial objection.)
You do not need to store the files on the SD Card. Each app has its own internal storage that is not accessible by any other apps. For more information see the official docs: http://developer.android.com/guide/topics/data/data-storage.html

Categories

Resources