如果我使用“可持久性尿皮术”将存储在云中但在本地缓存的文件时会发生什么?

发布于 2025-02-11 08:10:37 字数 1001 浏览 1 评论 0原文

基本上,我试图让用户从手机的图像库中选择图片,以用作我的应用程序中的背景图像。

我正在考虑使用可抑制功效。我想知道这是如何与本地缓存但存在于远程服务器上的文件一起使用的。

例如,Google Photos应用程序永久将照片存储在云中,但其中一些照片可在设备上本地获得(缓存)。如果用户选择最近的照片,我会通过perversistableuripermission获得访问权限,太好了!时间过去了,这张照片不再那么最近了,Google照片将其在本地删除。我还可以访问它吗?

更新:

我刚刚了解到,持久性URI的应用程序的数量

很长时间以来,是128 。 Android 11将其提高到512,对于Android 12也似乎是512。

您可以并且应该发布您不再需要这样的URI权限:

final int releaseFlags = intent.getFlags()
        & (Intent.FLAG_GRANT_READ_URI_PERMISSION
        | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

getContentResolver().releasePersistableUriPermission(fileUri, releaseFlags);

更新2:

对于拥有URI的应用程序也可以通过RevokeUriPermission来撤销该URI的许可。

Basically, I'm trying to let users choose pictures from their phone's image gallery to use as background images in my app.

I'm considering using takePersistableUriPermission. I'm wondering how this works with files that are cached locally, but exist on a remote server.

For example, the Google Photos app permanently stores photos in the cloud but some of those photos are available locally on the device (cached). If a user selects a recent photo, I gain access to it via takePersistableUriPermission, great! Time goes by and that photo is not so recent anymore and Google Photos removes it locally. Do I still have access to it?

Update:

I just learned that the number of persistable uri's your app can have is limited.

For a long time, it was 128. Android 11 raised it to 512, and it seems to be 512 for Android 12 as well.

You can and should release uri permissions you no longer need like so:

final int releaseFlags = intent.getFlags()
        & (Intent.FLAG_GRANT_READ_URI_PERMISSION
        | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

getContentResolver().releasePersistableUriPermission(fileUri, releaseFlags);

Update 2:

It's also possible for the app that owns the uri to revoke permission for that uri via revokeUriPermission.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文