title: Android 10: Delete denied by permission:android.permission.ACCESS_MEDIA_PROVIDER
body: <p>Target SDK in my project is 31 and when I'm trying to delete a file from DCIM directory, I'm getting following error such as <strong>delete denied by permission:android.permission.ACCESS_MEDIA_PROVIDER</strong>.
  Please consider file path like this: <strong>&quot;/storage/emulated/0/DCIM/Screenshots/pic1.jpg&quot;</strong></p>
  <p>I have tried so much to find the result every where including stack overflow, but didn't succeeded yet. Even I changed target SDK to lower 30 but not worked.</p>
  <p>Following are the solutions that I had already worked on but nothing works:</p>
  <p><strong>1.flags in manifest file</strong></p>
  <pre><code>android:requestLegacyExternalStorage=&quot;true&quot;
  android:preserveLegacyExternalStorage=&quot;true&quot;
  </code></pre>
  <p><strong>2.permissions in manifest file</strong></p>
  <pre><code>&lt;uses-permission
      android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;
      android:maxSdkVersion=&quot;40&quot;
      tools:replace=&quot;android:maxSdkVersion&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; /&gt;
  &lt;uses-permission
      android:name=&quot;android.permission.MANAGE_EXTERNAL_STORAGE&quot;
      tools:ignore=&quot;ScopedStorage&quot; /&gt;
  </code></pre>
  <p>Please find the attached code</p>
  <pre><code>val fileToDelete = File(&quot;/storage/emulated/0/DCIM/Screenshots/pic1.jpg&quot;)
  fileToDelete.delete()
  </code></pre>
  <p><em>NOTE: filepath is hardcoded only to explain better</em></p>
  <p>Please find the attached log</p>
  <pre><code>2022-03-21 11:22:35.331 8639-20226/com.filepickerdemo D/ContentResolver: delete denied by permission:android.permission.ACCESS_MEDIA_PROVIDER#content://media/external/images/media#_data = ?#/storage/emulated/0/DCIM/Screenshots/pic1.jpg
  </code></pre>
  <p>What else should I put in my code to solve this issue. Thanks in advance.</p>