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