No persistable permission grants found for URI
<p>I'm using the intent action <code>ACTION_GET_CONTENT</code>.</p>
<pre><code>Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(&quot;image/*&quot;);
startActivityForResult(i, 3);
</code></pre>
<p>I need to use the URI in onActivityResult for copying the image that a user chooses and compress the copied image.</p>
<p>But I'm getting this error even after taking uri permission using <code>takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)</code> in onActivityResult. This works well when I use the Intent action <code>ACTION_OPEN_DOCUMENT</code>.</p>
<p>Here is the stack trace:</p>
<pre><code>01-08 01:22:52.581 3838-4425/com.example.wallpaper E/AndroidRuntime: FATAL EXCEPTION: 
AsyncTask Process: com.example.wallpaper, PID: 3838                                                                         
java.lang.RuntimeException: An error occured while executing doInBackground()                                                                              
at android.os.AsyncTask$3.done(AsyncTask.java:304)                                                                              
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)                                                                             
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)                                                                             
at java.util.concurrent.FutureTask.run(FutureTask.java:242)                                                                              
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)                                                                              
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)                                                                              
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)                                                                              
at java.lang.Thread.run(Thread.java:818)                                                                           
Caused by: java.lang.SecurityException: No persistable permission grants     
found for UID 10151 and Uri 0 @ content://media/external/images/media/29                                                                              
at android.os.Parcel.readException(Parcel.java:1546)                                                                              
at android.os.Parcel.readException(Parcel.java:1499)                                                                              
at android.app.ActivityManagerProxy.takePersistableUriPermission(ActivityManagerNative.java:3977)                                                                              
at android.content.ContentResolver.takePersistableUriPermission(ContentResolver.java:1658)                                                                         
at com.example.wallpaper.ImageChooser.getBitmap(ImageChooser.java:249)                                                                              
at com.example.wallpaper.ImageChooser.access$000(ImageChooser.java:110)                                                                              
at com.example.wallpaper.ImageChooser$2.doInBackground(ImageChooser.java:298)                                                                              
at com.example.wallpaper.ImageChooser$2.doInBackground(ImageChooser.java:282)                                                                              
at android.os.AsyncTask$2.call(AsyncTask.java:292)                                                                              
at java.util.concurrent.FutureTask.run(FutureTask.java:237)                                                                              
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)                                                                               
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)                                                                             
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)                                                                           
at java.lang.Thread.run(Thread.java:818) 
</code></pre>