5

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

Surajkumar_cse
  • 165
  • 1
  • 11

1 Answers1

0

[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

Boken
  • 4,825
  • 10
  • 32
  • 42
  • Also I attached picture link with title " 1" So click it and match your manifest – Sheraz Ghani Jun 02 '22 at 05:41
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31922223) – Bharat Lalwani Jun 08 '22 at 06:27