Android Question File Type Returned by content chooser

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Hi,

when receiving a file image/* from content chooser, how can I know the original extension (gif,jpg or png, which are all valid images) ? It's needed because when receiving an image from that, is common to copy to a directory where the app could manipulate and to do this it's needed to know the extension... for example, if I copy a original .gif to .jpg the original image will be corrupted. Something like this (for filetypes gif and jpg for example...)

B4X:
Chooser1_Result (Success As Boolean, Dir As String, FileName As String) 'extension image/*

 if chooser1.success then
  
   file_extension = ?????
    
  if file_extension = "jpg" then
     file.copy(dir,filename,file.dirinternal,"temp.jpg")
  else
      if file_extension = "gif" then
           file.copy(dir,filename,file.dirinternal,"temp.gif")
      end if
  end if

  ....
end if

But... fiel_extension of content chooser is unknown... what to do in this case?
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Hi,

Can you try something like this?


B4X:
    Dim filename As String= "image.jpg"
    
 Dim extension As String
    
 Dim s() As String
 s = Regex.Split("\.", filename)
    
 If s.Length>0 Then
    extension=s(s.Length-1)   
 End If
    
 If extension="jpg" Then
    Log(extension)
 End If
 
Upvote 0
Top