I am working on an app where I want to be able to export and import some data from the app, on a .txt file. The minimum API of the app is 21.
The export part works w
I didn't find how I can get the file from the Uri.
There is no file. ACTION_OPEN_DOCUMENT
and ACTION_GET_CONTENT
do not open a file. They open a document. That document might be a file. It might not.
That Uri
might point to:
BLOB
column in a databaseHow can I get the real path of the file ?
You don't.
If you wish to only accept files, integrate a file chooser library instead of using ACTION_OPEN_DOCUMENT
or
ACTION_GET_CONTENT
. Just bear in mind that filesystem access to external storage is scheduled to go away with Android Q.
If you use ACTION_GET_CONTENT
, and the scheme of the Uri
that you get is file
, then getPath()
will be a filesystem path.
Otherwise, you need to understand that you have no idea where the document is coming from, and stop thinking in terms of "real path of the file". Use ContentResolver
and openInputStream()
to make a copy of the content to some file that you control, then work with that file.