title: How can I delete file on Android 11 (API 30) without system confirmation dialog?
body: <p>I have an app which records videos to shared MOVIES folder.</p>
  <p>I can delete those files on Android 11 (API 30) with <code>contentResolver.delete(uri, null, null)</code> method in my recorded videos activity.</p>
  <p>But if I reinstall the app then it looses permissions to those files... (so afwul) and in such case I need to do something like this:</p>
  <pre><code>try {
      context.contentResolver.delete(uri, null, null)
  } catch (exception: Exception) {
      if (exception is RecoverableSecurityException) {
          val intentSender = exception.userAction.actionIntent.intentSender
          intentSender?.let {
              callback?.startIntentSenderForResult(
                  intentSender,
                  requestCode
              )
          }
      }
  }
  </code></pre>
  <p>So it couldn't delete the file using <code>ContentResolver</code> because app was reinstalled and there is exception which we can catch and open the next annoying dialog for a user to confirm deletion (and for each file deletion it should be a different dialog, multiple deleting - no way)</p>
  <p><a href="https://i.stack.imgur.com/XlakG.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XlakG.png" alt="enter image description here" /></a></p>
  <p>Then I installed Explorer app from Google Play on this Android 11 device (emulator), when I opened it the app only asked for storage write permission (my app also does it) and this Explorer app could easily delete any file (including my record videos files) without any confirmation dialog.</p>
  <p>So how do they do it? Is it a hack or what is that?</p>
  <p>Link to the app <a href="https://play.google.com/store/apps/details?id=com.speedsoftware.explorer" rel="noreferrer">https://play.google.com/store/apps/details?id=com.speedsoftware.explorer</a></p>
  <p><strong>Update</strong></p>
  <p>VLC for Android can also delete any media file <a href="https://play.google.com/store/apps/details?id=org.videolan.vlc" rel="noreferrer">https://play.google.com/store/apps/details?id=org.videolan.vlc</a></p>
  <p>They also use content provider, so it's the same but it returns <code>true</code> unlike my app, why?</p>
  <pre><code>fun deleteFile(file: File): Boolean {
      var deleted: Boolean
      //Delete from Android Medialib, for consistency with device MTP storing and other apps listing content:// media
      if (file.isDirectory) {
          deleted = true
          for (child in file.listFiles()) deleted = deleted and deleteFile(child)
          if (deleted) deleted = deleted and file.delete()
      } else {
          val cr = AppContextProvider.appContext.contentResolver
          try {
              deleted = cr.delete(MediaStore.Files.getContentUri(&quot;external&quot;),
                      MediaStore.Files.FileColumns.DATA + &quot;=?&quot;, arrayOf(file.path)) &gt; 0
          } catch (ignored: IllegalArgumentException) {
              deleted = false
          } catch (ignored: SecurityException) {
              deleted = false
          }
          // Can happen on some devices...
          if (file.exists()) deleted = deleted or file.delete()
      }
      return deleted
  }
  </code></pre>
  <p><a href="https://github.com/videolan/vlc-android/blob/master/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt#L240" rel="noreferrer">https://github.com/videolan/vlc-android/blob/master/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt#L240</a></p>