How to create private folder in sdcard - android

My application is used for security purpose. so, from my application user captures photos that all photos are stored in a folder that folder should not access from any other application and should not give access when devices connect to computer system. If user wants to view these images he should access only from my application.

According to this guide, you can save files directly on the device's internal storage. By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed.
For example:
String FILENAME = "hello_file";
String string = "hello world!";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
MODE_PRIVATE will create the file (or replace a file of the same name) and make it private to your application. Other modes available are: MODE_APPEND, MODE_WORLD_READABLE, and MODE_WORLD_WRITEABLE.

The only way, AFAIK is to encrypt the files that you store. There is no way to prevent users mount the sdcard to access every file stored in it.

according to this related question, you can only create protected files in internal storage (not on the SD)...
Create Folder that can not accessible by any other application

Try following solution:
How to store a file in Hidden mode
Although it is not exactly what you want and I doubt whether it is possible or not. The best option would be to make it hidden but that also works with constraint (works for linux and not for Windows, still other applications can access the folder)
How to hide the folder of sdcard in android
How to make a file hidden in android sd card?

Its not possible to give no access to that folder when device connected to pc.. Also its not possible on sdcard also,
But you can use different format for images that can be opened only from your application, or you can encrypt images.
Or if you want to hide images from showing them into gallery, you can put a blank file with name as ".nomedia" in your folder.
But its not possible cause if u read docs about WRITE_EXTERNEL_STORAGE permission you will understand what I am saying. :)

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

How to delete file from SDcard when uninstalling the application

I have application that record a sound, I want to delete this sound file when uninstalling this application. how is that possible ?
You should store the files in the internal storage. Thus, when the application is removed, so are the files.
http://developer.android.com/guide/topics/data/data-storage.html#filesInternal
There are 2 ways to saved the file so it can be deleted upon uninstall
on the SD-card:
in an app only file note that it is deleted automatically only on API 8 and above.
// find or create private file need to be in a Context object
File root_private_SD_Card_file = getExternalFilesDir(null);
File myOwnFile = getExternalFilesDir("MyOwnFile") //
String path = myOwnFile.getAbsolutePath()
this method also hides the image video and audio files from other applications
2.
by storing directly to the device's storage from within a context
openFileInput(fileName);
[android developer's link][1]
This method can be problematic because device storage can be limited or occupied.
If the minSdk of your application is 8 you can use
context.getExternalFilesDir(null)
as the doc stands:
Returns the absolute path to the directory on the external filesystem
(that is somewhere on Environment.getExternalStorageDirectory()) where
the application can place persistent files it owns. These files are
private to the applications, and not typically visible to the user as
media.
When you uninstall the application, the related directory would be deleted (tipically the root would be com.yourdomain.yourappname).
If you have a Samsung phone with Android ICS, that does not work (I think it is a bug)

Is it possible to create shared preference files in sdcard

Can anyone help me ? Is it possible to create shared preference files in sdcard rather than on private path of an android application.
You cannot modify where shared preferences are stored.Its a private storage. if you want to use sd card use
Environment.getExternalStorageDirectory(). and get the path of directories stored in sdcard.
it is possible by reading&writing the xml file into the external storage ,but it's not the same as sharedPreferences. you will have to implement your own way , or use the android code of this class.
however , there are some disadvantage over using the internal storage:
anything you store on the sdcard is visible to every application and the end user can read it by just opening it.
only in the internal storage you get some sort of protection against reading the file , so that only rooted devices can read the files.
external storage can also be unmounted , so the data can sometimes be unreachable. you need to handle possible errors that can occur because of this.
uninstalling the app while the sd card is mounted means that the data will stay on the sdcard .

Files internal to applications

I read this sentence, form a book
"Files: Files internal to applications, which you can store on a
removable storage medium"
and I am confused, well I expect that "Files internal to applications" saved from my app that will be accessible only from my app. and that is true when you save them internally in the phone memory.
But as the sentence says , you can save files to the sdcard also. And that is great but I think that everyone with 'external storage read' privilege set in the manifest will be able to read your file, so that doesn't make it internal to the app, it makes it publicly available to everyone.
My question is:
Is there any way to store the files in the 'removable storage medium' -> sdcard and those files to stay available only to my app, others application to be prevented from reading the content ?
I know that if you put files in data/data//files these files are only available to the app with that package name
It is possible . For that you need to encrypt the data with some private key and write to SDCARD, when ever you want to process that data you have to decrypt it . So another app can't access your data without decrypt it.
Android Encryption Example.
store the files in the 'removable storage medium' -> sdcard and those files to stay available only to my app
I don't think so, For sdcard it is not possible.
The one way is store encrypted file in sdcard and key for it is you can put (keep) in your application's shared preference in private mode and decrypt the file from your application when you want to read it. But I think it some ugly way.

Is it possible to change the permission on files in an Android app's internal storage?

I downloaded a file with an app and stored it inside of its internal storage, but the file is set with -rw------- and I want to change those permissions so is it possible? I know that using external storage is an option but I want to know if I can do it with internal storage too. Thanks for the help.
Edit:
If it turns out that I can't change the permission is there some shared region of internal storage that I could use? I would like to not force the Android device user to have an SD card.
Internal storage is always private to your application.
I found out that the follow bit of code will change the permissions on the file based on what you set the second parameter to be.
FileOutputStream fileOutput = openFileOutput("myApp.apk", Context.MODE_WORLD_READABLE);
The four options for the second parameter are: MODE_PRIVATE, MODE_APPEND, MODE_WORLD_READABLE, and MODE_WORLD_WRITEABLE.

Categories

Resources