使用Intent.ACTION_OPEN_DOCUMENT_TREE
在"abc/bumbum"
文件夹中选择了子文件夹"Downloads"
。结果uri是:
content://com.android.providers.downloads.documents/tree/msd%3A127
在这个uri下,我现在拥有读写权限。
“ bumbum”文件夹包含另一个子文件夹“ test”。
如果要在“ test”文件夹中创建文件,如何用子文件夹“ test”更新返回的uri?
答案 0 :(得分:0)
String contentScheme = "content://com.android.providers.downloads.documents/tree/msd%3A127";
String folder = "test";
if (createDirectory(contentScheme, folder))
{
;
}
private boolean createDirectory ( String contentScheme, String folderName ) {
DocumentFile documentDir = DocumentFile.fromTreeUri(context, Uri.parse(contentScheme));
if ( documentDir==null )
{
Toast.makeText( context, "documentDir==null\n\n" + contentScheme, Toast.LENGTH_SHORT).show();
return false;
}
DocumentFile folder = documentDir.createDirectory(folderName);
if ( folder==null )
{
Toast.makeText( context, "documentsubDir==null\n\n" + folderName + "\n\n" + contentScheme, Toast.LENGTH_SHORT).show();
return false;
}
Toast.makeText( context, "created\n\n" + folder.getName() + "\n\n" + contentScheme, Toast.LENGTH_SHORT).show();
return true;
}