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

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'

Related

How to securely store application files within its package folder structure?

My question is pretty general; whenever an android app accesses internal storage environment path; its folder structure is created into device's "Android->Data->app_pakage".
Image files within this folder won't be viewed from gallery; which is fine.
There are lots of app which secures this files (Can't be opened directly from file manager);
Examples for this are music apps; they provide encoding of its downloaded files, so it can be accessed only from that app only. This encoding changes its extension
So my question is here, How this can be achieved?. I am looking for simplest solution, which don't require a high, complex encryption algorithms.
In-Short, I want to prevent users to access app files from file manager- internal storage
Please have a look at this link
https://developer.android.com/training/data-storage/files.html
Here there is detailed explanation.
To have files that can only be accessed from your app please use -
getFilesDir()
Returns a File representing an internal directory for your app.
Files saved here are accessible by only your app.

Only my application should have permission to access the files generated by app

My application generates some .csv files while running and these files are placed inside Android File system. These files are accessible outside the application also(as i can open these files in text editor and modify...)
Now I want that only my application should be able to read/write into these files.
Please help me in achieving this.
Thanks a lot.
These files are accessible outside the application also(as i can open these files in text editor and modify...)
Presumably that means you are placing them on external storage.
Now I want that only my application should be able to read/write into these files
Place the files on internal storage. This will prevent ordinary Android users from accessing the files except via your app.
Owners of rooted devices can get at those files, and if you are concerned about that scenario, then do not create any files at all, as owners of rooted devices can get to anything.
Also see article here: http://developer.android.com/training/basics/data-storage/files.html
It informs about internal vs external storage as well as making data public vs private for your app.

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.

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

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..

Android: Delete app associated files from external storage on Uninstall?

It'd be convenient if an application I'm writing stored some files to external storage permanently (so they persist after the application has been exited[destroyed]), but on an uninstall I'd like to do the decent thing and have these files removed to free up the storage.
Is there any way I can have these files removed on an uninstall?
If there isn't (and I'm skeptical), then I'll have to create these files each time. I'm trying to save start-up time and also occupy required space by having them exist permanently.
Note: I need to use external storage, so both internal storage or a DB would be inappropriate.
actually it is possible .
android will automatically remove files of the app in the external storage , but the files must be inside a specific path of the app :
"...../Android/data/APP_PACKAGE_NAME/"
where APP_PACKAGE_NAME is the application's package name.
another path that is automatically being emptied is :
"...../Android/obb/APP_PACKAGE_NAME/"
where APP_PACKAGE_NAME is the application's package name.
the data is for anything you wish.
the obb folder is for huge files that are downloaded using the play-store and the apk extension library . you are not supposed to create files there .
No, I don't believe so. Only files that you write to internal storage will be removed when your application is uninstalled (or if the user presses the 'clear data' button in the Application settings app).
Your app can't receive its own PACKAGE_REMOVED broadcast intent either, so you essentially have no notification that you're being uninstalled.
Yes, this is possible. Simply write your files to the external files directory:
File dir = getExternalFilesDir(null);
This will create a folder at /Android/data/your.package/. Note that this is not External as in sdcard, but it is publicly accessible. If a user uninstalls your app, this directory will also be removed, along with all of its contents.
Quoting from the blog post of CommonsWare
Internal storage: your file is deleted
External storage: if you wrote your file to a location rooted at getExternalFilesDir() or getExternalCacheDir(), your file is deleted. If you wrote your file elsewhere (e.g., Environment.getExternalStoragePublicDirectory()), your file is not deleted
Removable storage, prior to Android 4.4: removable storage is not officially accessible; if your file winds up out there, it should not be deleted when your app is uninstalled
Removable storage, Android 4.4+: AFAIK, if you write to a supported location (getExternalFilesDirs() or getExternalCacheDirs()), your file is deleted if that particular bit of removable storage is in the device at the time of uninstall

Categories

Resources