我正在使用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
}
}
我怀疑可以更改代码以选择文件夹而不是文件。 任何建议都会有所帮助. 请建议是否有任何其他方法来实现想要的。
谢谢
查看您发布的网址中的 github 项目,看起来无法实现这一点。我的声明基于类中的以下代码com.ipaulpro.afilechooser.FileChooserActivity
:
@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())
声明就知道了。