i'm very new to android dev... i wanna know what's the best way to hide an image in android. I have an app where i take a photo, and i want that photo, can only be display inside my app.
-
You could try encripting the images in some way. There are reports that .nomedia doesnt work on 4.0 onwards. http://stackoverflow.com/questions/10697276/android-nomedia-not-working-for-images – IAmGroot Oct 27 '12 at 14:36
-
There's some bugs with the media scanner on some api versions, but the .nomedia still works. One of the bugs is that creating a .nomedia file after some images were present in the folder hides future images but not older ones, but it can be fixed by forcing a rescan of all media (simply by deleting its data and cache works too). The solution is even simpler, add the .nomedia file before you start storing images in a folder to prevent them being taken by the mediascanner. That post addresses how to solve all this. – ZhDev Oct 27 '12 at 14:50
1 Answers
The best way would be using the internal storage of the device. According to the developer's site:
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).
You can find all the details here: Using the Internal Storage
Bear in mind that there are some things that you should take into account; for example if that photo you mention is being taken through a camera intent the image will have to be first saved in a public folder (ie. in the external storage) for the camera to work properly and then you should move it to the internal storage (or copy it and then delete the original).
There are other methods:
- You could also try saving the images in the external storage (accesible by others) but name the files with a preceding dot in the file name to make them invisible, but any app can access the file if they know the filename, and most file managers can show hidden files
- Add a ".nomedia" file inside the folder to prevent the gallery from showing your pictures.
- Name your files with random strings without extensions.
It really depends if you want to make them totally inaccessible to other apps or if hiding it a little bit it's enough

- 244
- 1
- 7
-
+1 for the answer. But i am having a small doubt. The doubt is out of the scope but hope it will be considered. Suppose i am having a file which i am storing in external storage with the file name preceeding dot. This helps the file to be invisible and what is .nomedia file? Should it be created while creating this file (preceeded by a dot) in the java code? – G_S Oct 27 '12 at 14:31
-
From the same link used in the answer: "Include an empty file named .nomedia in your external files directory (note the dot prefix in the filename). This will prevent Android's media scanner from reading your media files and including them in apps like Gallery or Music." Basically include one single blank file called .nomedia at the top folder you are using to store the pictures (the first time you access the folder or when you create it), that will prevent the gallery from showing all the images stored there. – ZhDev Oct 27 '12 at 14:42
-
1As an additional comment to that, the (default) gallery doesn't show hidden files either, so if all your files are named ".image1.jpg", ".image2.jpg", ".reallyCoolPic.jpg", they are all hidden and you wouldn't need the .nomedia file. – ZhDev Oct 27 '12 at 14:45
-
To make sure other applications can't access the photo, do we need to encrypt the photo files too? What is the best way to encrypt it? – HendraWD Jul 27 '17 at 10:04