Android Question [SOLVED] ContentChooser select does not return an event

ThePuiu

Active Member
Licensed User
Longtime User
I'm trying to select an image to transfer to the server. I use ContentChooser as in the example:
B4X:
Sub PanelBrowse_Click
    PhotoLoaded = False
    Dim CC As ContentChooser
    CC.Initialize("CC")
    CC.Show("image/*", "Select an image!")  
End Sub

Sub CC_Result(Success As Boolean, Dir As String, FileName As String)
    If Success Then
       Msgbox2Async("Image " & FileName & " was selected!","Atentie!","Ok","","",LoadBitmap(File.DirAssets,"exclamation.png"),False)
        File.Copy(Dir, FileName, File.DirInternal, "sesizare.jpg")                      
        ImageViewPoza.Bitmap = LoadBitmap(Dir, FileName)
        PhotoLoaded = True
    Else
        Msgbox2Async("No image was selected!","Atenttion!","Ok","","",LoadBitmap(File.DirAssets,"exclamation.png"),False)
    End If
End Sub

On the first try, the application does not reach the CC_Result subroutine! None of the messages are displayed! Then, every time I try, it works perfectly. After closing the application (or reinstall it) and reopening it, it behaves identically: on the first try it doesn't work, then it works every time. What am I not doing well?
 
Last edited:

roumei

Active Member
Licensed User
I'm not sure what's wrong with your code but here's what works for me. ccImage is defined in Process_Globals, is initialized only once and is used with Wait For.
B4X:
' Process_Globals
Dim ccImage As ContentChooser

Sub lblScreenshot_Click
    If ccImage.IsInitialized = False Then ccImage.Initialize("ccImageResult")
    ccImage.Show("image/*", "Choose Image")
    Wait For(ccImage) ccImageResult_Result (Success As Boolean, Dir As String, FileName As String)
    If Success = True Then
        ' ...   
    End If
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…