how to hide images from android gallery - android

One part of my current project is downloading images from URL then saving to SDCard. But the problem is all of saved images in sdcard is displayed in android gallery page. What I want is "I don't want all of my saved images in android gallery."

Add ".nomedia" file. Did not work? Try the second option.
Save your files to a folder that starts with ".", e.g., /sdcard/.myimages/

You can create .nomedia file using this code:
String NOMEDIA=".nomedia";
File Folder = new File(Environment.getExternalStorageDirectory() + "/mydir");
if(Folder.mkdir()) {
nomediaFile = new File(Environment.getExternalStorageDirectory() + "/mydir/"+ NOMEDIA);
if(!nomediaFile.exists()){
nomediaFile.createNewFile();
}
}

I found a simple way(I think so).
Create a folder in 'Android' folder(where data & obb folders are present) and put your media(pics,videos, etc.,) in the folder you've created.
Gallery app ignores that 'Android' folder. Simple :-)

its so late and i know other answers are complete but i think putting .nomedia file makes all pictures in that particular folder hidden :
just change extension of image file programmatically and this way gallery cant detect it as an image . eg if your image is "pic1.jpg" rename it to "pic1.aaa";
and when you want show it again rename it again

Related

how to get directory of images to access via code

I want to add images with my app. I see option to add images in res/drawable folder. But I have lot of images. How can I access the directory?
e.g. to access sdcard location I can use
File directory = new File(
android.os.Environment.getExternalStorageDirectory()
+ File.separator + AppConstant.PHOTO_ALBUM);
But I have images in drawable folder which will be with app. So how to access directory in android project. So that I can use something like File[] listFiles = directory.listFiles();
Is there better way to save and access images through app?
The solution I can suggest you is to store your images into "Asset" folder in your project and you can easily access all the images at once by following these steps:
Create a folder named "images" in your asset folder.
Copy all your images in that "images" folder.
3.Get your images list like this:
String[] images =getAssets().list("images");
ArrayList<String> listImages = new ArrayList<String>(Arrays.asList(images));
4.Now set the images to your "imageview" like this:
InputStream inputstream=mContext.getAssets().open("images/"
+listImages.get(position));
Drawable drawable = Drawable.createFromStream(inputstream, null);
imageView.setImageDrawable(drawable);
you can access all you images in drawable folder with :
getResources().getDrawable(R.drawable.name_of_drawable)
and also if you want access or load many images , you can use same names ( with postfix / prefix ) and load theme in a loop easily

Android hide image from user gallery

i'm using the following phonegap build plugin:
com.chanthu.evri.gcs-file-transfer version="1.0.0"
to download images on devices. The download is ok but the images are visible in user's standard gallery myApp folder. How can i save the images without creating such a gallery ?
The path I use to save them is:
cdvfile://localhost/persistent/myApp/
The path on the android device become:
/storage/sdcard0/myApp/
You have to create a .nomedia file and put it into myApp folder using the below code.
try
{
File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/myApp");
if(!dir.exists())
{
dir.mkdirs();
String filenameForNoMedia4 = Environment.getExternalStorageDirectory().getAbsolutePath()+".nomedia";
FileOutputStream outForNoMedia4 = new FileOutputStream(filenameForNoMedia4);
}
}
catch (Exception e)
{
}
But for this you need add a permission to androidManifest.xml file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Android is Linux so whatever works to hide files and folders in Linux works on Android, too.
If you want to hide all the data in a folder, just add a .nomedia file to that folder. If, however, you want to hide a specific file, just prepend a . to it's name.
FOLDER 1
|
-- .file1.txt
-- file2.txt
-- FOLDER 2
|
-- .nomedia
-- file3.txt
-- file4.txt
In the above scenario, all the content under FOLDER 2 is hidden and only file1 from FOLDER 1 is hidden.
Create a .nomedia file and put this in the folder where you store images.
This file hides the folder and its ages from showing up in gallery

Cordova app downloaded images showing in gallery

My application downloads a set of images and stores them in the internal storage by creating a folder.
The problem is the images are being shown in the gallery. This should not happen, is there a way to programatically hide the images but still be usable by the app?
Thanks in advance.
EDIT:
This is only happening to the android version of the app. In the iOS it is not showing in the Camera Roll.
This depends where you download the images: If you download them on your Pictures folder or inside of a public folder from sdcard/internal memory then MediaScanner scan them so your pictures will be visible in the Gallery app.
To avoid this you can try one of the following solutions:
Add a .nomedia file inside your destination folder
OR
Download your pictures in app cache directory by using LocalFileSystem.TEMPORARY.
Something like
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(fs) {
fs.root.getDirectory("media", {create: true}, function(fileDirectoryEntry) {
// var destFile = fileDirectory + "/" + filename;
// downloadPicture(srcUrl, destFile);
});
});
The downside of this solution is that when the app is removed, your pictures are deleted as well.

Adding a folder to the Application folder

I've used application folder
data/data/com.xxx.xxx/databases/Customer.db
to store a database,it works fine and i could open and used it,but i wanted to add multiple folders to this path like
/data/data/com.xxx.xxx/databases/b36f6e58-0971-4f79-aca0-dada4201d886/Customer.db
but when i download the database and put it on the path and when i want to open it, it throws Exception that couldn't open the database.i have also try downloading the db ,check and makeDir the path then move db to the path but it doesn't solve the issue.
is there anything wrong with adding another folder in application folder or am i missing something? Any help would be appreciated.
Try this way:
File newDir = new File(getFilesDir(), "newDir");
if (!newDir.exists()) {
newDir.mkdirs();
}
File inside newDir can be accessed with openFileInput/openFileOutput. For both you need a context

Make picture available only for my Android application

I have an application which has loads of pictures. The total picture is saved in an SD card due to large number of picture. The main problem is that the pictures are available in gallery. I want a way to hide the picture from the gallery but must be available for my application.
I did put " . " in front of the file name to make it hidden
but the images were not displayed in may application also!
Anyone.. help.. please
thanks..
Gallery handles all media files it knows about, so if you want it to stay away of your assets you got two solutions. First, add .nomedia file to the folder with your images, and Gallery should skip it (most image viewers would honor .nomedia, yet there's no guarantee). Other solution is to use some own, proprietary file format, so Gallery or other tools won't be able to process it. I'd recomment .nomedia if that's sufficient solution.
Add .nomedia file into the image folder. The important thing is that, the folder should be empty, when you add .nomedia file. If the folder contains some images before adding '.nomedia' file, the gallery will not hide those images, and it will hide the images added after '.nomedia' file. So The first file added to the image folder should be '.nomedia'.
Hope dis will help you
Thankx,
This line of code can add the .nomedia file in your directory and makes your images hidden from the gallery
String NOMEDIA=" .nomedia";
File Folder = new File(Environment.getExternalStorageDirectory() + "/mydir");
if(Folder.mkdir()) {
nomediaFile = new File(Environment.getExternalStorageDirectory() + "/mydir/"+ NOMEDIA);
if(!nomediaFile.exists()){
nomediaFile.createNewFile();
}
}
i think the place where you save the images matter, try to save them into application cache directory, or files directory.
you can get access to cache directory using : getCacheDir() in your activity.
and your files directory: getFilesDir()
these two directories must not be visible or accessible to any other applications expect your application,
I used assets to accomplish this in my app.

Categories

Resources