The following is my requirement: I have a checkbox in my activity. If the checkbox is checked, I will add a '.nomedia' file to hide all the photos in my folder. If the checkbox is unchecked, I will delete the '.nomedia' file, to display all the photos in the folder. My problem is, though the creation/deletion of '.nomedia' file is successful, the hiding/unhiding of the images are not happening in the android gallery app. How can I force the gallery app to show/hide the folder contents according to my checkbox state?
The following is my code:
CheckBox checkBox = (CheckBox) findViewById(R.id.checkBox1);
if (checkBox.isChecked()) {
hideFolder();
} else {
unHideFolder();
}
private void hideFolder() {
File targetDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + CONSTANTS.MYFOLDERPATH);
File noMediaFile = new File(targetDir, ".nomedia");
try {
if (!noMediaFile.exists()) {
noMediaFile.createNewFile();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
private void unHideFolder() {
File targetDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + CONSTANTS.MYFOLDERPATH);
File noMediaFile = new File(targetDir, ".nomedia");
if (noMediaFile.exists()) {
noMediaFile.delete();
}
}
Aucun commentaire:
Enregistrer un commentaire