I can't delete file from sdcard.
File toDelete = new File(fname);
boolean result=toDelete.delete();
The result is false. Reads and writes of the same file is working in same app running. No opened streams. No exceptions raised. I have tried to make it writable just before deletion this way
toDelete.setWritable(true);
with no effect. How does it possible that the system can write and read, but can not delete the same file???
use below code it may help you.
File fdelete = new File(file_dj_path);
if (fdelete.exists()) {
if (fdelete.delete()) {
System.out.println("file Deleted :" + file_dj_path);
} else {
System.out.println("file not Deleted :" + file_dj_path);
}
}
Refresh gallery after delete image
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
check this: https://stackoverflow.com/a/10716773/1168654
Try doing this
File fileToDelete = new File(YourPath);
boolean deleted = fileToDelete.delete();
Remount your card again and check
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With