Home > front end >  How to get File from DocumentFile in android version 29 for File Manager App?
How to get File from DocumentFile in android version 29 for File Manager App?

Time:11-18

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.

CodePudding user response:

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.

CodePudding user response:

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.

  • Related