如何列出Android Q(API级别29)中的所有内部存储文件夹? [英] How to List all Internal Storage Folders in Android Q (API Level 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 .这将为您提供所选directory
的URI
,一旦您拥有URI
,您就可以访问该directory
的所有子级.来自文档
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.
在github上还有 ActionOpenDocumentTree 示例应用程序,展示了如何实现此功能.
There is also ActionOpenDocumentTree sample app on github which shows how to implement this feature.
这篇关于如何列出Android Q(API级别29)中的所有内部存储文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!