权限在应用程序重新启动时拒绝访问图片URI(Permission Denial accessing picture URI on app restart)

编程入门 行业动态 更新时间:2024-10-28 00:27:40
权限在应用程序重新启动时拒绝访问图片URI(Permission Denial accessing picture URI on app restart)

如果没有偶尔的头发拉动体验,它不会是Android编程...

目前使用模拟器...

这显然是一个新的特点:

Permission Denial: opening provider com.google.android.apps.photos.contentprovider.impl.MediaContentProvider from ProcessRecord{6ebfe9e 22355:xxx/u0a140} (pid=22355, uid=10140) that is not exported from UID 10068

在任何情况下都可以访问EXTERNAL_STORAGE。

场景:

用户选择一张图片(使用ACTION_GET_CONTENT),活动结果很好,图片显示在我的应用上下文中。 图片的URI保存在应用程序数据库中。 应用程序重新启动。 尝试访问相同的 URI并获得上面的权限拒绝异常。

然后在原始图片选择活动结果上尝试takePersistableUriPermission ,并引发异常,指示没有持久权限。

编辑:好吧,我已经实现了接受的答案(但只是使用OPEN_DOCUMENT),不再尝试将结果URI投影到媒体路径。 因此,在悔改的行为中,我再次说明:

我永远不会尝试将URI转换为媒体存储路径。

(即使GET_CONTENT和投影曾经工作 - 好吧,我不能帮助自己。)

It wouldn't be android programming without the occasional hair-pulling experience...

Using emulator at the moment...

This evidently is a new feature:

Permission Denial: opening provider com.google.android.apps.photos.contentprovider.impl.MediaContentProvider from ProcessRecord{6ebfe9e 22355:xxx/u0a140} (pid=22355, uid=10140) that is not exported from UID 10068

Access to EXTERNAL_STORAGE has been granted in all cases.

Scenario:

User selects a picture (using ACTION_GET_CONTENT) and activity result is good and picture is displayed within my app context. URI to picture is saved in app DB. App is restarted. Attempt to access same URI and get the above Permission Denial exception.

Then tried takePersistableUriPermission on original picture selection activity result and that throws an exception indicating there are no persistable permissions.

EDIT: Ok, I've implemented the accepted answer (but just using OPEN_DOCUMENT) and no longer attempt to project the resultant URI into a media path. So in an act of repentance, I state again:

I will never attempt to translate a URI into a Media Store path.

(Even though GET_CONTENT and projecting once worked - OK I can't help myself.)

最满意答案

确实。

用ACTION_GET_CONTENT获得的Uries只在你的应用程序运行时才有效。

如果你想持续uri开始ACTION_OPEN_DOCUMENT_TREE,然后在onActivityResult使得获得的权限持久。

看看takePersistabkeUriPermission()。

(或类似的东西)。

您不需要外部存储权限等。

Indeed.

Uries obtained with ACTION_GET_CONTENT are only valid as long as your app runs.

If you want to persist the uri start with ACTION_OPEN_DOCUMENT_TREE and then in onActivityResult make the obtained permissions persistent.

Have a look at takePersistabkeUriPermission().

(Or something like that).

You do not need external storage permissions and such.

更多推荐

本文发布于:2023-07-26 08:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1272929.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:启动时   应用程序   权限   图片   URI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!