使用SAF列取Download文件夹非媒体内容的权限与API使用问题
开发核心目标
本次开发核心目标为基于SAF(Storage Access Framework,存储访问框架),实现从Download文件夹中列取非媒体类文件内容的功能。
现有参考实现代码
当前参考的SAF目录申请逻辑代码如下:
public void openDirectory(Uri uriToLoad) { // Choose a directory using the system's file picker. Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); // Provide read access to files and sub-directories in the user-selected // directory. intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // Optionally, specify a URI for the directory that should be opened in // the system file picker when it loads. intent.putExtra(EXTRA_INITIAL_URI, uriToLoad); startActivityForResult(intent, 500); }
开发调试中遇到的两类问题
- 第一类问题:通过SAF调起系统文件选择器定位到Download文件夹时,界面上的「使用此文件夹」按钮处于禁用状态,无法正常获取该目录的访问授权
- 第二类问题:参考Android官方能力说明,尝试调用MediaStore.Downloads API查询下载目录内容时,返回结果的游标计数为0,无法明确该API的正确适用场景与调用约束
内容的提问来源于stack exchange,提问作者Abdul
相关产品推荐
相关产品推荐

