Android Question File Type

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Hello all,

I have a routine where an user can use the content chooser to select a media file, that will be managed by the app. But it's normal that the user selects a mpeg file as an image, an image as a gif and so on. I developed separated buttons for GIF, JPG and MPEG but this don't guarantees that the user will choose the correct media type. And when I filter the target content using the chooser mime type, many gallery interfaces hide valid files even with valid mimes and the user cant choose them.
I noticed that some programs like WhatsApp use only one button, and detect the file type doing the right process, what is the best solution.
How can I detect the choosen file type (then I could use Chooser.Show("*/*","Select") and apply the correct treatment later)?

Anybody?
 

Marcos Alves

Well-Known Member
Licensed User
Longtime User
You can try to extract the file extension from the returned URL. Just don't assume that it will always be available.
Thanks @Erel . I'm studying to parse the bytes of the file and find the mime signature, but I'll spend some time to do this. As soon as finished, I'll post a class here - I think that it's the best technique as doesn't depends on the file extension and will give the real file mime type, but besides that I didn't find any similar code doing this routine in community.
 
Upvote 0
Top