java 如何在android中浏览文件夹并获取所选文件夹的路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31937456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to browse folder in android and get the path of folder selected
提问by I DAE
When I click a button,show a file browser,I can choose a folder and return it's path.I get this path to copy file to that path.
当我点击一个按钮,显示一个文件浏览器时,我可以选择一个文件夹并返回它的路径。我得到这个路径来将文件复制到那个路径。
But I have no idea of How I could implement this.
但我不知道如何实现这一点。
I have yet looking for this question in Stackoverflow but I haven't find a clear answer to my question.
我还没有在 Stackoverflow 中寻找这个问题,但我还没有找到我的问题的明确答案。
I saw some libary of filebrowserview like "https://github.com/psaravan/FileBrowserView",but not work.
我看到了一些像“ https://github.com/psaravan/FileBrowserView”这样的文件浏览器库,但不起作用。
回答by Adam Fr??ko
Use intent for that!
为此使用意图!
First start start activity for result like this:
首先开始启动活动,结果如下:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);
Override this method in your activity, it will get called when activity you just started returns. You can handle result codes such as canceled or successful.
在您的活动中覆盖此方法,它会在您刚开始的活动返回时被调用。您可以处理诸如取消或成功之类的结果代码。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String Fpath = data.getDataString();
//TODO handle your request here
super.onActivityResult(requestCode, resultCode, data);
}
Another approach is to use library such as NoNonsense-FilePicker.
另一种方法是使用诸如NoNonsense-FilePicker 之类的库。