[英]adding “uses-permission” in manifest doesn't work
SLOVED 变身
Sending the intent like 发送意图像
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
In the onActivityResult
method 在
onActivityResult
方法中
imageUri = data.getData();
getContentResolver().takePersistableUriPermission(imageUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
I have found that this is a common issue. 我发现这是一个常见问题。 I am getting a
java.lang.SecurityException: Permission Denial:
error when trying to userImg.setImageURI(tmp.photo);
我在尝试获取
userImg.setImageURI(tmp.photo);
时遇到java.lang.SecurityException: Permission Denial:
错误userImg.setImageURI(tmp.photo);
in my code. 在我的代码中。 I have tried many solutions found on SO but nothing.
我已经尝试了许多在SO上找到的解决方案,但是什么也没有。 I also tried using glide but no luck there.
我也尝试使用滑行,但那里没有运气。 The uri is read into an object, which I store in memory on runtime, and I request it with
tmp.photo
. uri被读入一个对象,该对象在运行时存储在内存中,并使用
tmp.photo
请求它。 I checked with logging that the Uri
is passed successfully into the photo
attribute. 我用日志记录检查了
Uri
已成功传递到photo
属性。 What can I do? 我能做什么?
these are into my manifest. 这些都进入了我的清单。
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
My code is very simple. 我的代码很简单。
ImageView userImg = (ImageView) findViewById(R.id.userImg);
userImg.setImageURI(tmp.photo);
where tmp.photo
is a Uri object. 其中
tmp.photo
是Uri对象。 This generates all of these 这将产生所有这些
Unable to open content: content://com.android.providers.media.documents/document/image%3A156
java.lang.SecurityException: Permission Denial:
opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord
{74dbab7 13175:com.example.gus.uniman/u0a168} (pid=13175, uid=10168) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
at android.os.Parcel.readException(Parcel.java:1684)
at android.os.Parcel.readException(Parcel.java:1637)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:4199)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:5478)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2239)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1517)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1131)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:984)
at android.content.ContentResolver.openInputStream(ContentResolver.java:704)
at android.widget.ImageView.getDrawableFromUri(ImageView.java:900)
at android.widget.ImageView.resolveUri(ImageView.java:871)
at android.widget.ImageView.setImageURI(ImageView.java:490)
at com.example.gus.uniman.PersonDetails.onCreate(PersonDetails.java:78)
at android.app.Activity.performCreate(Activity.java:6682)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
06-07 19:24:36.919 13175-13175/com.example.gus.uniman W/ImageView: resolveUri failed on bad bitmap uri: content://com.android.providers.media.documents/document/image%3A156
06-07 19:24:37.030 13175-13207/com.example.gus.uniman D/OpenGLRenderer: endAllActiveAnimators on 0x76706ab800 (ListView) with handle 0x768d4df4a0
You only have rights to the content identified by the Uri
: 您仅有权使用
Uri
标识的内容:
In your original component (eg, the activity that got the Uri
via onActivityResult()
of ACTION_GET_CONTENT
), or 在您的原始组件中(例如,通过
ACTION_GET_CONTENT
onActivityResult()
获得Uri
的活动),或
In any components that you pass the Uri
to, if you include FLAG_GRANT_READ_URI_PERMISSION
in the Intent
used to start that component, and 在与您传递的任何部件
Uri
到,如果包括FLAG_GRANT_READ_URI_PERMISSION
在Intent
用于启动该组件, 并
Only while your process is around 只有在您的过程中
In your case, somewhere along the line, you violated those rules. 就您而言,您违反了这些规则。 Perhaps you passed the
Uri
to another component without FLAG_GRANT_READ_URI_PERMISSION
, or perhaps you saved the Uri
to disk and attempted to use it again later. 也许您将
Uri
传递给了没有FLAG_GRANT_READ_URI_PERMISSION
其他组件,或者您FLAG_GRANT_READ_URI_PERMISSION
Uri
保存到磁盘上并稍后尝试再次使用。
See this blog post for more about Uri
access lifetime. 有关
Uri
访问寿命的更多信息,请参Uri
博客文章 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.