ARTICLE AD BOX
I want to call ContentResolver.query on a URI. Since I can't pass the URI returned by an ACTION_OPEN_DOCUMENT_TREE Intent to ContentResolver.query because it is a document tree and not a document, I'm doing the following first:
if(DocumentsContract.isTreeUri(uri)) uri = DocumentsContract.buildDocumentUriUsingTree(uri, DocumentsContract.getTreeDocumentId(uri));When done like that, I can pass the converted uri to ContentResolver.query and it works fine.
But there is one problem: Apparently, isTreeUri just checks if something like /tree/ occurs in the URI and then returns true which leads to a lot of false positives, e.g. let's suppose I want to examine the subdirectory in foo in the document tree specified by uri using ContentResolver.query so I first do something like this to append the subdirectory foo to the document tree uri which was returned by ACTION_OPEN_DOCUMENT_TREE:
DocumentFile targetUri = DocumentFile.fromTreeUri(this, uri); DocumentFile subDir = targetUri.findFile("foo"); Uri subDirUri = subDir.getUri();The literal representation of subDirUri will now be something like this:
content://com.android.externalstorage.documents/tree/primary%3AMyDir/document/primary%3AMyDir%2FfooSince there is the substring /tree/ in this URI, DocumentsContract.isTreeUri returns true for this URI but of course it's not really a tree because I can pass it to ContentResolver.query just fine and in this case I must NOT pass it to buildDocumentUriUsingTree because that will fail so I'm looking for a way to safely tell whether a URI is a document tree or not. Apparently isTreeUri isn't really up for the job...
