文件选择器选择文件夹(android)

时间:2016-03-04 11:20:53

标签: android

我正在使用afilechooser来实现此目的。默认情况下,这是为了选择文件夹中的项目,并为您提供用户选择的路径。

但我想用它作为文件夹选择器,用户从Android设备的内部存储器中选择一个位置,然后应用程序将文件保存在该位置。

所以我该怎么做。

我为此目的使用的代码是 -

private void showChooser() {
    // Use the GET_CONTENT intent from the utility class
    Intent target = FileUtils.createGetContentIntent();
    // Create the chooser Intent
    Intent intent = Intent.createChooser(
            target, getString(R.string.chooser_title));
    try {
        startActivityForResult(intent, REQUEST_CODE);
    } catch (ActivityNotFoundException e) {
        // The reason for the existence of aFileChooser
    }
}

我怀疑代码可以更改为选择文件夹而不是文件。任何建议都会有所帮助。请建议是否有其他方式来实现所需。

谢谢

1 个答案:

答案 0 :(得分:0)

查看您发布的网址中的github项目,看起来并不像这样。我的声明基于com.ipaulpro.afilechooser.FileChooserActivity class:

中的以下代码段
@Override
public void onFileSelected(File file) {
    if (file != null) {
        if (file.isDirectory()) {
            replaceFragment(file);
        } else {
            finishWithResult(file);
        }
    } else {
        Toast.makeText(FileChooserActivity.this, R.string.error_selecting_file,
                Toast.LENGTH_SHORT).show();
    }
}

只需查看if(file.isDirectory())声明。

相关问题