Android Question Using image from Content Chooser

barx

Well-Known Member
Licensed User
Longtime User
Wondering what would be the correct way to do this.

My app is to input data and select images that will then be uploaded to a host server.
What would be the correct way of getting the user to select an image and then caching it for upload?

From what I have read I need to use ContentChooser and so far have this...

B4X:
Sub btnPic_Click

    Dim btn As Button
  
    btn = Sender
    CurrentPic = btn.Tag
    CC.Show("image/*", "Choose Image")
End Sub


Sub CC_Result (Success As Boolean, Dir As String, FileName As String)
    If Success Then
        Dim TargetDir As String
        Dim TargetExt As String

        ToastMessageShow(TargetExt, False)
        If File.ExternalWritable Then TargetDir = File.DirDefaultExternal Else TargetDir = File.DirInternal
             File.Copy(Dir, FileName, TargetDir, CurrentPic & ".jpg")
        Log(File.ListFiles(TargetDir))
    End If
End Sub

Now this works fine so long as the file is a .jpg; but what if the user was to select, say a png from file browser. From what I can tell, there is no easy way to get the file extension as the CC params return a content:// that does not divulge the extension.

There are up to 9 images the user needs to select. One at a time from different buttons. So, I need to copy them to a temp dir until the input is complete and then when ready, upload them.

Thoughts?
 
Last edited:

barx

Well-Known Member
Licensed User
Longtime User
because File.Copy requires a set Filename which in turn requires an extension.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
As the OP says then. How would be best to go about the situation ;)
 
Upvote 0
Top