title: How to delete files in mediastore in API 29+?
body: <p>I'm building gallery app and I have tried to delete a image in mediastore by using <code>contentResolver().delete()</code>. but it throws an exception.
  How can I resolve it? I'm using API 29.</p>
  <p>My code:</p>
  <pre class="lang-java prettyprint-override"><code>public static void removeFile(Context context, String uriStr) {
      Uri uri = Uri.parse(uriStr);
      context.getContentResolver().delete(uri, null, null);
  }
  </code></pre>
  <p>Error log:</p>
  <pre><code>2020-11-09 08:17:54.806 12098-12098/com.example.mygallery E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.mygallery, PID: 12098
      android.app.RecoverableSecurityException: com.example.mygallery has no access to content://media/external/images/media/39
          at android.app.RecoverableSecurityException$1.createFromParcel(RecoverableSecurityException.java:197)
          at android.app.RecoverableSecurityException$1.createFromParcel(RecoverableSecurityException.java:194)
          at android.os.Parcel.readParcelable(Parcel.java:3281)
          at android.os.Parcel.createExceptionOrNull(Parcel.java:2368)
          at android.os.Parcel.createException(Parcel.java:2357)
          at android.os.Parcel.readException(Parcel.java:2340)
          at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
          at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
          at android.content.ContentProviderProxy.delete(ContentProviderNative.java:624)
          at android.content.ContentResolver.delete(ContentResolver.java:2289)
          at android.content.ContentResolver.delete(ContentResolver.java:2255)
          at com.example.mygallery.database.FileHelper.removeFile(FileHelper.java:72)
          at com.example.mygallery.database.ImageDAOImpl.deleteMediaFile(ImageDAOImpl.java:83)
          at com.example.mygallery.fragment.HomeFragment$1.onClick(HomeFragment.java:165)
          at android.view.View.performClick(View.java:7448)
          at android.view.View.performClickInternal(View.java:7425)
          at android.view.View.access$3600(View.java:810)
          at android.view.View$PerformClick.run(View.java:28305)
          at android.os.Handler.handleCallback(Handler.java:938)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:223)
          at android.app.ActivityThread.main(ActivityThread.java:7656)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
  </code></pre>