I am developing an app which hides image files in stock gallery app. For the same, I am creating a .nomedia file and asking MediaScanner to update.
This technique works for a case where I have to show the hidden files, i.e. delete .nomedia file and scan every file present in that folder to show in gallery. But when I want to hide images, putting a .nomedia file and then asking MediaScanner to scan all files in that folder does not hide those pics from gallery.
I am using following code to scan file
private void refreshPic(String path) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(path);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
}
Am I doing it the right way? Or does removing files from Media Store needs some other stuff?
Testing device: Nexus 5 (4.4.2)
Thanks.