问题
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.
回答1:
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
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.
There is also ActionOpenDocumentTree sample app on github which shows how to implement this feature.
来源:https://stackoverflow.com/questions/61420960/how-to-list-all-internal-storage-folders-in-android-q-api-level-29