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
I have Used Three Approaches:
- folder Name with dot
.TafheemReels
- image Extension :
.falseExtension
file Path Looks like :
/storage/emulated/0/Download/.TafheemReels/mypicture.falseExtension
- show the image with picasso.
The saving method :
public static void saveImageToDownloadStorage(Context mContext, Bitmap bitmap, String fileName) {
class saveThread extends Thread {
@Override
public void run() {
super.run();
FileOutputStream outStream = null;
File outFile;
try {
outFile = reelImagePath ( fileName);
outStream = new FileOutputStream(outFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
outStream.flush();
outStream.close();
MediaScannerConnection.scanFile(mContext, new String[]{outFile.getPath()}, new String[]{"image/jpeg"}, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
saveThread thread = new saveThread();
thread.setDaemon(true);
thread.start();
}
public static File reelImagePath (String fileName){
String root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() + "/.TafheemReels";
File dir = new File(root);
if (!dir.exists()) {
dir.mkdirs();
}
String filename = String.format("%s.falseExtension", fileName);
File outFile = new File(dir, filename);
return outFile ;
}
And the image showing with picasso :
File localPath = reelImagePath("mypicture");
Uri uri = Uri.fromFile(localPath);
Picasso.with(mContext).cancelRequest(imageView);
Picasso.with(mContext).load(uri).into(imageView);
In this way, I found that Picasso do not look after the file extension.
And your Image file is hidden forever from the gallery app.
© 2022 - 2024 — McMap. All rights reserved.