Android Question Get file type or extension from content chooser

kstainsb

Member
Licensed User
Longtime User
I am using content chooser to get any file (MIME type */*). Then copying the file to a local file and storing the file in a database. Later I’m trying to open it in an external viewer. Using an intent, copying the file from the database to the content folder then opening it.

The problem seems to be that the file type is not known. Content chooser returns a URI but not details of the file type (e.g. a pdf file loses its .pdf at the end). If I manually add the correct file extension (eg .pdf or .jpg etc) it opens fine.

How can I find the filetype of a file selected with content chooser? I saw an earlier post with a function that gets the file name from a uri, but also the warning to not use it! And it didn’t work for my local files anyway..
 

kstainsb

Member
Licensed User
Longtime User
My solution so far is to run the routine to get the filename in the content chooser result. If it can’t do it, I’m going to not store the file in the database, since I can’t reliably open it to view it later.

Thanks anyway!
 
Upvote 0
Top