DocumentFile.delete() fails to delete an existing file

47 views Asked by At
DocumentFile df = DocumentFile.fromSingleUri(context, uri);
if (df != null && df.exists()) {
    if (df.delete()) {
        //succeeded
    } else {
        //failed
    }
} 

df.delete() of the above code keeps failing.

uri: content://media/external/video/media/80
df.getName():  foo_2023_09_14_223303_backup.mp4

I checked the file and made sure it does exist:

[![enter image description here][1]][1]

I suspect that I am missing something fundamental. Could anyone shed some light on this?

Update [2023-09-19]: From logcat:

java.lang.UnsupportedOperationException: Unsupported call: android:deleteDocument
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:174)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
    at android.content.ContentProviderProxy.call(ContentProviderNative.java:732)
    at android.content.ContentResolver.call(ContentResolver.java:2450)
    at android.provider.DocumentsContract.deleteDocument(DocumentsContract.java:1469)
    at androidx.documentfile.provider.SingleDocumentFile.delete(SingleDocumentFile.java:102)

Please note the file was created by the app via MediaStore, so the app has permission to access the storage. [1]: https://i.stack.imgur.com/O07G2.png

0

There are 0 answers