我正在使用意图操作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)
答案 0 :(得分:14)
但即使在使用onActivityResult中的takePersistableUriPermission(uri,Intent.FLAG_GRANT_READ_URI_PERMISSION)获取uri权限后,我也收到此错误。
takePersistableUriPermission()
适用于ACTION_OPEN_DOCUMENT
以及属于Storage Access Framework的其他操作,不适用于ACTION_GET_CONTENT
。
答案 1 :(得分:-3)
您是否在清单文件中声明了权限?
请尝试添加这两项权限。
<uses-permission android:name="android.permission.READ_USER_DICTIONARY">
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY">
有关详细信息,请参阅:Content Provider Basics
希望它有所帮助。