I have a simple file inside either the apps getExternalFilesDir
or a user selected folder. When i create a subfolder and try to move the file from the parent folder into that newly created subfolder moveDocument() fails.
Logcat says
W/DocumentsContract: Failed to move document
java.lang.IllegalArgumentException: Unknown authority
at android.content.ContentResolver.call(ContentResolver.java:2412)
at android.provider.DocumentsContract.moveDocument(DocumentsContract.java:1520)
Both DocumentFiles give an empty string when i try .getUri().getAuthority()
// file and subfolder are under the same parent
DocumentsContract.moveDocument(context.getContentResolver(),
file.getUri(),
subfolder.getParentFile().getUri(),
subfolder.getUri());
Both DocumentFiles exist, i even create files inside that subfolder and that works fine, but i need to move this one from the parent into the sub.
edit:
// if user selected
DocumentFile dir = DocumentFile.fromTreeUri(context, persistedUri);
// if 'internal'
DocumentFile dir = DocumentFile.fromFile(getContext().getExternalFilesDir(null));
DocumentFile subfolder = dir.createDirectory(name);
DocumentFile file = dir.createFile("video/mp4", vidname);
// Uris internal
file:///storage/emulated/0/Android/data/com.foo.bar/files/
file:///storage/emulated/0/Android/data/com.foo.bar/files/vid
file:///storage/emulated/0/Android/data/com.foo.bar/files/1656602728866.mp4