我有一个应用程序,当我按下按钮时,它应该打开文件夹选择器并允许用户仅浏览和选择一个文件夹。然后我想获取文件夹的路径,以便我可以对其进行一些操作。
我试过使用这段代码:
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "*/*"
startActivityForResult(intent, 8778)
但它不起作用。
你能帮我提供一些代码吗?谢谢你。
最佳答案
it should open the folder picker and allow the user to browse and select a folder ONLY
Android 最接近类似的东西是
ACTION_OPEN_DOCUMENT_TREE
.这允许用户选择一个文档树,它可以是文件系统上的目录、云存储提供商提供的东西或其他文档树结构。Then i want to get the folder's path so that i can do some manipulation with it.
如果“路径”是指“文件系统路径”,则有两个问题:
您可能想花一些时间了解 the Storage Access Framework一般和
ACTION_OPEN_DOCUMENT_TREE
in particular .
关于Android:仅文件夹选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57027099/