I am developing File Manager, I have one issue in android version 30, when I get listFile() of OTG path its not return file, the only way to get all files is from DocumentFile, but now I want to get file as File from that DocumentFile how do I get, plz support me.
Asked
Active
Viewed 179 times
0
-
`when I get listFile() of OTG path` listFile()? Dont know that function. What is full path you use? Please post your code. – blackapps Nov 18 '21 at 07:31
-
Be serious: if you want to make a file manager app then use DocumentFile all the way. No need for using the File class. DocumentFile is slow. So better use DocumentsContract as it is twenty times faster. – blackapps Nov 18 '21 at 07:45
2 Answers
0
You don't. There's no promise that there is an actual File anywhere, it could be backed by a content provider calculating it at runtime, or reading it from a db. Since a File can only represent a file on disk, there's no way to convert from a DocumentFile to a File.

Gabe Sechan
- 90,003
- 9
- 87
- 127
-
-
@blackapps Doesn't matter- DocumentFile has no way to convert to a File because there's no promise its backed by a File. The idea is you use a DocumentFile as is and don't need to know (or have access to) how its actually stored. – Gabe Sechan Nov 18 '21 at 15:13
0
USB OTG drives are often not mentioned any more in getExternalFilesDirs().
So you have no path.
Only with SAF ACTION_GET_DOCUMENT_TREE you can get an uri to the drive or folders on the drive.
Now its pretty easy to convert such an uri to a flie system path.(Look at all kinds of getRealFileForUri() implementations).
But even if you manage to get a path it is not usable.

blackapps
- 8,011
- 2
- 11
- 25