我使用SAF,其中允许用户选择目录/文件夹,然后我想在选择后在Textview中显示其名称。我使用下面的代码来启动intent。
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, 1);下面的代码是针对onActivityResult的
if (resultCode == RESULT_OK && requestCode == 1) {
DocumentFile documentFile = DocumentFile.fromTreeUri(this, uriTree);
textInfo.append(documentFile .getName() + "\n");
}根据指导更改了问题,现在正在返回foldername。
发布于 2020-01-21 01:24:33
使用DocumentFile.fromTreeUri()获取您在onActivityResult()中获取的树Uri上的DocumentFile。然后,在DocumentFile上调用getName()以获取与该树相关联的显示名称。
https://stackoverflow.com/questions/59825703
复制相似问题