It works perfectly fine for android 10 but does not work in android 11 after some research I found out that we must ask for user consent, so I have gone through some video and I didn’t understand how to so can anyone help me out here!
File file = new File(childItem.getPath());
file.delete();
if (file.exists()) {
try {
file.getCanonicalFile().delete();
if (file.exists()) {
deleteFile(file.getName());
}
} catch (IOException unused) {
unused.printStackTrace();
}
}
2
Answers
For Andorid11; you need user-interaction for modify or delete any files from external storage. You need to use
createDeleteRequest
for deletion of file.You can follow this steps:
now create delete request like this;
now handle result in your
onActivityResult
;I hope this helps you.
try this:
Step 1
Step 2
Step 3
finally, you can replace ‘MediaStore.Audio’ to ‘MediaStore.Video’
I hope this helps you.