Android Question Getting a file (not an image) from a passed in content uri

Acuario

Active Member
Licensed User
Longtime User
I am receiving a content uri as an input from another app and I want to access the file (it is a text file), either read the contents, or copy it to somewhere else.
The uri I receive is content://com.pocketfms.easyvfr4.provider/s3e_external/Android/data/com.pocketfms.easyvfr4/files/Outbox/plan.gpx

I want to access the plan.gpx file that is passed in on the uri.
The examples I have found all relate to loading bitmaps from the uri but I want the text file (or to read its contents)

Can anyone explain how to do this?
 
Solution
if another app is sharing a resource with your app, you can simply change references to loading a
bitmap to loading a text file. you can use file.readstring() or inputstream.readbytes(). if you use
inputstream, then you have to perform an additional step to convert to utf8 text (or you could just save
the bytes and read as text at your leisure).

the key involves handling whether the intent filter used send or view as its intent action, as access to
the uri is different depending on the action. since you seem to have the uri already, it sounds like you
have that under control. but you need to be able to handle both eventualities if you were writing a general
use app.

drgottjr

Expert
Licensed User
Longtime User
if another app is sharing a resource with your app, you can simply change references to loading a
bitmap to loading a text file. you can use file.readstring() or inputstream.readbytes(). if you use
inputstream, then you have to perform an additional step to convert to utf8 text (or you could just save
the bytes and read as text at your leisure).

the key involves handling whether the intent filter used send or view as its intent action, as access to
the uri is different depending on the action. since you seem to have the uri already, it sounds like you
have that under control. but you need to be able to handle both eventualities if you were writing a general
use app.
 
Upvote 0
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…