KitKat,存储访问框架,特定文件权限? [英] KitKat, Storage Access Framework, Specific File Permission?

查看:161
本文介绍了KitKat,存储访问框架,特定文件权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,该应用程序实现了自己的文件选择界面,这是该应用程序正常运行的要求.

I have an app that implements its own interface for selecting files, which is a requirement for the app to work properly.

在KitKat中,(外部)SD卡上的文件必须先通过存储访问框架获得许可,然后才能进行修改.

In KitKat, files on an (External) SD-Card need to have permission given via the Storage Access Framework before they can be modified.

由于这些受限制的文件仍然可以自由读取,因此不会阻止我的应用显示它们.但是,一旦用户选择对其中一个文件执行操作,我是否可以使用Storage Access Framework提示用户特定的权限请求?

Since these restricted files are still freely readable, it doesn't stop my app from displaying them. But once the user selects to perform an operation on one of these files can I prompt the user with a specific permission request using the Storage Access Framework?

下面是文档中的示例.这将返回一组所有可能的图像.显然,如果我已经可以识别要请求其权限的特定图像,则我不想向用户显示所有图像.还有其他过滤器可以缩小向用户提供的内容的范围吗?

Below is the sample from the documentation. This returns a set of all possible images. Obviously I don't want to show the user all images, if I already can identify the specific image that I'm requesting permission for. Are there any other filters that would narrow down what's presented to the user?

(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");

推荐答案

不幸的是,KitKat中的SAF没有这种高级功能.

Unfortunately SAF in KitKat doesn't have that advanced capability.

根据需要,启动API 24,您可以通过调用

Depending on what you need, starting API 24 you can ask user to grant you permission to manage files in SD card by calling https://developer.android.com/reference/android/os/storage/StorageVolume.html#createAccessIntent(java.lang.String).

在API 21-23中,您可以引导用户通过调用 https://developer.android.com/reference/android/content/Intent.html#ACTION_OPEN_DOCUMENT_TREE .

In API 21 - 23 you can direct user to grant you the entire SD card by invoking https://developer.android.com/reference/android/content/Intent.html#ACTION_OPEN_DOCUMENT_TREE.

这将授予您通过SAF访问sdcard的权限,并且您可以利用SAF轻松显示/修改SD卡中的内容.

That will grant you access through SAF to the sdcard, and you can leverage SAF to show/modify contents in SD card easily.

这篇关于KitKat,存储访问框架,特定文件权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆