如何在 Android Q(API 级别 29)中列出所有内部存储文件夹? [英] How to List all Internal Storage Folders in Android Q (API Level 29)?

查看:35
本文介绍了如何在 Android Q(API 级别 29)中列出所有内部存储文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手,想在 android studio 中制作一个文件管理器.在 getExteralStorageDirectory 被弃用后,我在列出 API 级别 29 中的所有设备文件夹时遇到问题.

I am new in programming and want to make a file manager in android studio. I am facing problems in listing all device folders in API level 29 after getExteralStorageDirectory was deprecated.

推荐答案

根据文档,您必须使用 ACTION_OPEN_DOCUMENT_TREE.这将为您提供所选目录URI,一旦您拥有URI,您就可以访问该目录的所有子目录.来自文档

According to the documentation, you will have to use ACTION_OPEN_DOCUMENT_TREE. This will provide you with the URI of selected directory, once you have the URI then you can access all the children of that directory. From docs

文件管理和媒体创建应用程序通常管理目录层次结构中的文件.为了在您的应用程序,使用 ACTION_OPEN_DOCUMENT_TREE 意图操作,它允许用户授予对整个目录树的访问权限.然后您的应用程序可以访问所选目录中的任何文件及其任何子目录.

Grant access to a directory's contents

File management and media-creation apps typically manage groups of files in a directory hierarchy. To provide this capability in your app, use the ACTION_OPEN_DOCUMENT_TREE intent action, which allows the user to grant access to an entire directory tree. Your app can then access any file in the selected directory and any of its sub-directories.

还有 ActionOpenDocumentTree 展示了 github 上的示例应用程序实现此功能.

There is also ActionOpenDocumentTree sample app on github which shows how to implement this feature.

这篇关于如何在 Android Q(API 级别 29)中列出所有内部存储文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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