9

I am developing an android application where it will select some photos from the gallery and hide them,

i am able to select particular picture from gallery and store it in my app and delete it from gallery,but a person can see those pictures if he opens my app folder in sdcard ,so how do i store them such that even if a person checks my sdcard then he should not be able to detect those pictures ?

Mahantesh M Ambi
  • 786
  • 1
  • 13
  • 25

6 Answers6

11

The only secure way to do this is to encrypt the image data yourself and remove the original files, leaving only your application able to decrypt the files.

Take a look at How to encrypt file from SD card using AES in Android? to see how this can be done.

As an additional step, you can also use any number of the other answers to hide the encrypted files

Community
  • 1
  • 1
Guykun
  • 2,780
  • 23
  • 28
8

If you want to prevent Gallery from showing images from your app's folder, you can put a file named .nomedia in that folder.

Source: https://stackoverflow.com/a/6713863/450534

If you want to hide the folder from apperaring in say, a File Manager, then ensure your folder starts with a period (.). For example, if the folder is called myfolder, it should be created as .myfolder

Source: https://stackoverflow.com/a/5878270/450534

Please note, that a user can change the settings of the File Manager to show hidden files and folder. For that, there is no solution.

Community
  • 1
  • 1
Siddharth Lele
  • 27,623
  • 15
  • 98
  • 151
  • Thanks for your reply but file manager in my android phone can show '.' prefixed folders,so anyone can see my pictures within that folder,so how to make pictures invisible even in file manager also? – Mahantesh M Ambi Nov 08 '12 at 06:08
  • @MAHANTESH: As mentioned at the end of the answer, File Managers can show hidden folder as per their settings. Under the circumstances, I think **Guykun** has the best solution for you. – Siddharth Lele Nov 08 '12 at 06:13
  • yeah i will try to encrypt and store it into my app folder and delete that image from the sdcard,but don't know whether it will work for images or not,as that encryption and decryption is for .txt files – Mahantesh M Ambi Nov 08 '12 at 06:27
  • @MAHANTESH: Well, for one, that post is for encrypting an Image and the OP has pointed out that it worked for him. I don't see why it shouldn't work for you too. ;-) Give it a try and see how it goes. – Siddharth Lele Nov 08 '12 at 06:29
  • :well i tried Guykun's method of encrypting but it is taking lot of time for encrypting bunch of selected images,isn't there any better way of achieving it,i mean instead of encrypting bunch of images,encrypting folder ?i tried that too but its giving me an error.,i even commented on the post mentioned by Guykun but no response. – Mahantesh M Ambi Nov 13 '12 at 11:04
  • @MAHANTESH: I guess this is a small trade-off for making sure nothing else can see your images. The best thing I can suggest is to either optimize the process as much as you can, or just rely on hiding the folder. – Siddharth Lele Nov 13 '12 at 11:07
  • what do u mean by rely on hiding the folder?that is what i wanted to achieve,i mean its part of my question,1)we can prevent images being displayed in gallery by creating folder prefixed with ".",2)then user must also not be able to see those hidden images by exploring the sdcard,i.e making folder hidden,so how do we make it hidden or encrypted ? – Mahantesh M Ambi Nov 13 '12 at 11:13
  • i am using samsung galaxy ace,in that even if we just open file manager then we will be able to see "."prefixed folders,.even in htc mobiles if we explore sdcard using ES file manager then we will be able to see those ,so only option left with us is by encrypting the folder is what i think,what do say about this?sorry for troubling u a lot on this – Mahantesh M Ambi Nov 13 '12 at 11:20
  • And one small input,i downloaded an app where it has an feature of hiding images,i explored my sdcard by mounting it on my pc and noticed that they were creating one folder containing .HId files of each hidden images,and another folder called ".nomedia",so do you have any idea of what .HID file is? – Mahantesh M Ambi Nov 13 '12 at 11:28
  • I can't say what that folder is, but the .nomedia file ensures that media files from that folder wont show up in gallery. – Siddharth Lele Nov 13 '12 at 11:59
  • @MahanteshMAmbi can u pls tell me how u have done image encryption and decryption doing individual image encryption and decryption will take a lot of time if there a re bunch of images how u resolve your issue ? – user3233280 Dec 22 '14 at 18:40
2

If you want to hide folder just add '.' as prefix to folder name.

Deepika
  • 566
  • 2
  • 10
  • Thanks for your reply but my concern is that even if i create a '.' prefixed folder so that pictures within that folder will not be visible in gallery,another person can explore my sdcard and view my pictures,so how do i prevent that?Is there any code snippet for encrypting images ? – Mahantesh M Ambi Nov 08 '12 at 06:04
1

If you want to prevent Gallery from showing images from your app's folder, you can put a file named .nomedia in that folder.

If you want to hide the folder from apperaring in say, a File Manager, then ensure your folder starts with a period (.). For example, if the folder is called myfolder, it should be created as .myfolder

File sdCard = Environment.getExternalStorageDirectory(); File dir = new File(sdCard.getAbsolutePath() + "/.myFolder" );

  • This is like temporary solution, If user changes settings to show hidden files in file manager then user will be able to view all the images hidden, best way to solve this is by encrypting it and storing the encrypted files hidden, so even if the user see hidden folder then he wont be able to see the images – Mahantesh M Ambi Dec 15 '14 at 07:39
0

See this . that are perform with one step more. they are hiding data as well as folder also.

How to hide a folder in sdcard in android

Community
  • 1
  • 1
Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
0

Use your sd card folder path as

Environment.getExternalStorageDirectory().toString()+context.getPackageName+"//data//data//"+"(.folderName)";

this will provide you maximum security to your images, if user phone is not rooted this path is safe from all aspects.

Mohd Mufiz
  • 2,236
  • 17
  • 28
  • Thanks for your reply,Here we are just creating many sub folders but i think it makes no difference to the person who is exploring my sdcard,eventually he will be able to see my pictures :( – Mahantesh M Ambi Nov 08 '12 at 06:16