'How do I find if a root uri tree exist?

I get a tree uri from OPEN_DOCUMENT_TREE, and want to know if folder exsist in case user deleted. I tried doc == null from treeUri and single, and also exists but they dont they both show not null when folder is deleted. Thanks



Solution 1:[1]

Try to list the content of the tree.

If the tree does not exist anymore you will get an exception or a null cursor.

Solution 2:[2]

Did you try to do something like that? with the findFile() method?

Uri treeUri = uri;
DocumentFile root = DocumentFile.fromTreeUri(this, treeUri);
if (root.findFile("Foldername") == null) { //create folder }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 blackapps
Solution 2 Gustavo Lizárraga