I\'m using Android file selection and selecting files from app storage (images, videos, documents). I have an function \"getPath\" . Im getting path from uri. I have no problem
I have no problem with gallery images or download documents
You will, on many devices.
But when i select a file from google drive i cant get path
There is no path. ACTION_GET_CONTENT
does not allow the user to choose a file. It allows the user to choose a piece of content. That content might be a local file. That content might also be:
You have two main options. If you only want files, then use a third-party file chooser library to replace all of the code in your question.
Or, if you still want to use ACTION_GET_CONTENT
or ACTION_OPEN_DOCUMENT
, you can take the Uri
that you get from data.getData()
in onActivityResult()
and do two things with it:
First, use DocumentFile.fromSingleUri()
to get a DocumentFile
object pointing to that Uri
. You can call getName()
on the DocumentFile
to get a "display name" for the content, which should be something that the user will recognize.
Then, use a ContentResolver
and openInputStream()
to get at the content itself, similar to how you might use a FileInputStream
to get at the bytes in a file.