Create Non Readable Directory in Android - android

I want to create a directory in device internal storage, which should be hidden for all the user from other apps like file explorer or file manager. Should I use any encryption technique for this?

If the folder is on internal storage, it will already be hidden from file explorer and file manager apps, unless the user has a rooted phone. If he has a rooted phone, there is no way you can hide the folder from him.

Related

Hiding a folder in android not using "." extension

How can I hide a folder in android? I am downloading some data from the app which must be accessible only through my application. Currently, I am hiding folders by putting "." extension to the folder name and saving it in the app directory. But it will get visible when switching on "show hidden option" in file managers and enter the particular app data. Kindly suggest some methods by which we can hide data similar to what we see in amazon prime application and all.
Unless the user roots their device all internal files are accessible only to your app. Beyond that, there is no use case and no acceptable reason to hide files from the person who actually owns the device.
Hiding a folder in android not using “.” extension
you can use internal storage as an alternative to hide the folder, if the device is rooted don't allow the app to be installed, if the user roots the device after app install no matter what you do things will be accessible.
//Create internal dir;
File mydir = context.getDir("DIR_NAME", Context.MODE_PRIVATE);
Currently solved my issue by saving files to Internal Storage.
We can use either
File file = new File(context.getFilesDir(), filename);
or
File mydir = context.getDir("DIR_NAME", Context.MODE_PRIVATE);
for saving it in internal directory.
But if rooted device the issue will persist

Pick a directory/file using Intent.ACTION_CREATE_DOCUMENT (Storage Access Framework)

As explained here:
http://www.doubleencore.com/2014/03/android-external-storage/
or here:
http://www.androidpolice.com/2014/02/17/external-blues-google-has-brought-big-changes-to-sd-cards-in-kitkat-and-even-samsung-may-be-implementing-them/
KitKat is limiting writing to the secondary external storage to the package specific directory (although some developers have found a workaround already...). With Samsung using the sdcard as a secondary external storage and rolling out it's 4.4.2 update this has become a major issue for many apps.
My app has a save as function that allows the user to pick an arbitrary directory to save a file to.
I'm using Intents like org.openintents.action.PICK_DIRECTORY, com.estrongs.action.PICK_DIRECTORY or my integrated file explorer to pick a directory. The user is of course free to pick any path on the sdcard too but because of the new restrictions with KitKat the actual store operation fails if the directory is one my app has no write access to.
I need an alternative way to pick a directory on KitKat so that the user doesn't get an error message when he/she tries to save to sdcard. That could be achieved by letting them pick only directories the app has write access to.
I tried to use Intent.ACTION_CREATE_DOCUMENT like so:
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT)
.addCategory(Intent.CATEGORY_OPENABLE)
.setType(attachment.getContentType())
.putExtra(Intent.EXTRA_TITLE, attachment.getName());
startActivityForResult(intent, RequestCodes.MSG_CHOOSE_DIRECTORY);
This works fine and I can write to the file the user picked BUT I only get to pick certain directories. E.g. for a pdf file it will return the download directory (matching Environment.DIRECTORY_DOWNLOADS), for jpg it will allow me to pick the download directory and the Google drive(s). It does however not give me the option to pick other folders on the primary external storage nor the package specific directory on sdcard (I tried different content types like "*/*" or DocumentsContract.Document.MIME_TYPE_DIR but to no avail).
So what I'm looking for is a way to let the user pick a directory on the primary external file system (as in returned by Environment.getExternalStorageDirectory() which is in fact internal storage) plus all the directories the framework would give me access to in the secondary external storage in order to save a file in that directory. Whether the user picks a directory or a file doesn't matter, the app would either use its own file name or the one the user picked.
Alternatively knowing how certain apps found a way around the new write restrictions would of course be a viable option too ;-). ES File Explorer e.g. can write any file to any directory on sdcard as I can confirm from my own tests on an unrooted S4 with sdcard.
Have you tried MIME_TYPE_DIR ?
intent.setType(DocumentsContract.Document.MIME_TYPE_DIR);//For API 19+
Edit:
Document Provider
To see external storage in the DocumentsUI (eg file picker dialog), you have to enable "Show advanced devices" in the DocumentsUI settings.
This is a user setting, so it can only be changed manually by the user.
As explained in this in depth article, if you are requesting android.permission.WRITE_EXTERNAL_STORAGE then
the permissions of primary external storage have not changed; they behave the same in 4.4 as they did before.
It is only secondary external storage that is affected by the changes to KitKat - the only directory you have access to on secondary external storage is one dedicated to your app. They also mention that on Samsung devices SD card is considered secondary external storage.

I want to password protect my local phone directory folder in android

I want to password protect my local phone directory folder
This folder (directory) has been created by my application at run time with password protection.
My application can open this folder and used for self.
Any one can't open this folder manually. It is possible in android.
Thanks in advance.
This is not possible on Android.
You could create your folder on the internal memory, so that only your app can access it on normal devices. However, anyone with a rooted device will be able to browse your folder using a file manager, and other apps will also be able to read its contents if given root access.
A folder on the external storage is accessible to all apps with the READ_EXTERNAL_STORAGE permission, so you'll want to avoid using that.
At any rate, there is no 100% effective way to secure your folder such that only your app can access it.
However, you could try encrypting your data. This is what many apps like whatsapp do. Even when Whatsapp backs up the chats to the external storage, it is AES encrypted so that while others can access the data, they can't read it without decrypting it first. I would recommend that your try encryption

If an app stores file on sdcard, can a user access them?

I just need a confirmation. If my app saves data to the phone's sdcard (/sdcard/com.example.myapp/file.mp3), can a user browse to such folder on the card and mess with the files (delete, rename, etc.)? I cannot find such info on the developer's site.
Thanks
Yes he can, there is no problem whatsoever. He will be able to see the files and modify them via the built in file manager, via code or from the PC when the device is connected.
Yes he can modify the files on the sdcard. You can verify it by e.g installing Astro and browse the sdcard, and modify files on your phone.
The SD card is capable of storing files with crypto protection called CPRM. Most devices that use SD cards don't bother to support it. Mere mortals such as ourselves cannot obtain keys to use the CPRM features on the card.

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