问题
I'm using the intent action ACTION_GET_CONTENT
.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(i, 3);
I need to use the URI in onActivityResult for copying the image that a user chooses and compress the copied image.
But I'm getting this error even after taking uri permission using takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
in onActivityResult. This works well when I use the Intent action ACTION_OPEN_DOCUMENT
.
Here is the stack trace:
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)
回答1:
But I'm getting this error even after taking uri permission using takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION) in onActivityResult.
takePersistableUriPermission()
is for ACTION_OPEN_DOCUMENT
and other actions that are part of the Storage Access Framework, not for ACTION_GET_CONTENT
.
回答2:
Have you declared the permissions in your manifest file ?
Please try to add these two permissions.
<uses-permission android:name="android.permission.READ_USER_DICTIONARY">
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY">
For more information please see this: Content Provider Basics
Hope it helps.
来源:https://stackoverflow.com/questions/34664915/no-persistable-permission-grants-found-for-uri