Android 10: contentResolver.delete() is not deleting file from the file system

Viewed 518

I am using MediaStore.Files for creating my file in InternalStorage/Documents/MyFolderName/xyz.pdf

using

ContentValues contentValues = new ContentValues();
        contentValues.put(MediaStore.Files.FileColumns.DISPLAY_NAME, fileName);
        contentValues.put(MediaStore.Files.FileColumns.MIME_TYPE, fileType);
        contentValues.put(MediaStore.Files.FileColumns.IS_PENDING, 1);
        contentValues.put(MediaStore.Files.FileColumns.RELATIVE_PATH, dstPublicDirectory + File.separator + dstSubDirectory);

        // Getting content uri for the file

        Uri dstFileUri = resolver.insert(MediaStore.Files.getContentUri("external"), contentValues);

I am able to create that xyz.pdf file

but, in order to delete that file I am using

 getActivity().getContentResolver().delete(fileUriToDelete, null, null);

the above is deleted from the database of MediaStore.Files but it is not able to delete that file in the filesystem.

As the file is still available in: InternalStorage/Documents/MyFolderName This is happening only in Android 10. In Android 11, that file is deleted from filesystem as well as MediaStore.Files db

1 Answers

[Kindly make Sure To Set Your Manifest Same as it , Same this issue i was facing My files was deleting on Android 11 but not deleting on Android 10 then I enable status of and add this tag So And Specify Write Permission with
<android:requestLegacyExternalStorage="true"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" android:maxSdkVersion="28"/>

1

Related