我正在使用意图操作ACTION_GET_CONTENT.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(i, 3);
我需要使用onActivityResult中的URI来复制用户选择的图像并压缩复制的图像.
但即使在onActivityResult中使用takePersistableUriPermission(uri,Intent.FLAG_GRANT_READ_URI_PERMISSION)获取uri权限后,我也会收到此错误.当我使用Intent动作ACTION_OPEN_DOCUMENT时,这很有效.
这是堆栈跟踪:
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)