0

Ok, so I have a Uri object of type content://, I need to convert it to a File object.

I tried

File file = new File(uri.getPath())   //and 
File file = new File(uri.toString())
  • Can you also add full path of file? – Hammad Zafar Bawara Sep 09 '22 at 11:15
  • i think this answer can help you. https://stackoverflow.com/a/52095352/4592885 – Mohammad Fallah Sep 09 '22 at 12:22
  • I think this answer can help you. https://stackoverflow.com/a/52095352/4592885 – Mohammad Fallah Sep 09 '22 at 12:23
  • @snachmsm no. that works for files. I am working with directories – Noel Dallas Sep 09 '22 at 12:35
  • 'I am working with directories" -- since your question does not contain a [mcve], I am going to guess that you are using `ACTION_OPEN_DOCUMENT_TREE` / `ActivityResultContracts.OpenDocumentTree`. There is no conversion to a `File` possible for that, in large part because there is nothing forcing the user to choose some directory on a filesystem that you can read from and write to. They could choose some document tree from a cloud storage provider, or an encrypted storage provider, or a network file server -- anything that has a `DocumentsProvider` registered on the device. – CommonsWare Sep 09 '22 at 13:52

0 Answers0