Search code examples
androidandroid-imageandroid-gallery

How to hide image from Gallery in Android?


I am downloading images from server and saving it in internal storage. But i want to hide those images from the Gallery. How can i do that?

I have heard that naming folder with .DirName hides the images but it doesn't work in my case. (Phone NOT Rooted)

public void myDownload(String myURL) {

    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(myURL));
    //request.setTitle("File Download");
    //request.setDescription("Downloading....");

    //request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
    request.allowScanningByMediaScanner();
    //request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
    String nameOfFile = URLUtil.guessFileName(myURL, null, MimeTypeMap.getFileExtensionFromUrl(myURL));

    //request.setDestinationInExternalPublicDir(Environment.getExternalStorageDirectory().getPath() + "/KiiTTimeTableData/" + year + "/" + branch + "/" + section + "/", nameOfFile);
    //request.setDestinationInExternalPublicDir("/MyDataFinal/", nameOfFile);
    request.setDestinationInExternalPublicDir("/KiiTTimeTableData/Data/", nameOfFile);

    DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
    manager.enqueue(request);
}

Solution

  • You can try to create a file name .nomedia (include dot in prefix) in your photos folder. This will prevent Android's media scanner from reading your media files and including them in apps like Gallery or Music.

    And another way you can try is encrypt your file, read this article: How to encrypt file from SD card using AES in Android?