The following is a brute force routine I have used in the past to get the file extension:
(Note: this is written off the top-of-my-head. There might be some typo's)
Sub GetFileExt(FileName As String) as String
this routine will not work. When came from gallery thru content chooser, filename is an url relative to gallery app and will not have a name with extension. Its something like this:
The solution is to get the file, write as bytes with a generic name, parse it and identify the signature of each type (jpeg,mpeg,gif) ... I think that if the content chooser has image/* parameter, it's possible to get gif, jpg or png for example. Like @Erel
already told in a post, there is no problem if you copy a png image as jpg BUT if it's a gif? You will loose data of course. And more: jpg image has rotation parameter and sometimes it's needed to rotate before loading on the screen. Then, IF your content chooser is image/* it's really needed to know the extension of source file to proceed the correct image processing.
For now, my solution is to separate: image/jpg and image/png from image/gif , with different content choosers/routines in the activity.