Android Question ContentChooser

Guenter Becker

Active Member
Licensed User
Hello,
I am working on an app using ContentChooser to get images from the Gallery. To open the Chooser I use this code:
Open ContentChooser:
Private Sub BTGallery_Click
    CC.Show("image/*", "Bitte Bild wählen:")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    If Success = True Then
        zimvImage.SetBitmap(LoadBitmap(Dir,FileName))
        TabHost1.CurrentTab=2
    Else
        xui.Msgbox2Async(LastException,"501: Programmfehler!", _
            "OK","","",Main.imgError)
    End If
End Sub

The code is working well. In origin the sub is marked as resumable.

Question:
What to do if the user opens the Chooser and decides to close it without choosing an image? There is no cancel button. If I am using the standard back button or the close button of the navigation bar the chooser is closed but my app is closed to.
How can it made be possible to close the chooser and to come back to the active B4XPage? B4A snipped will be welcome.
 

klaus

Expert
Licensed User
Longtime User
The problem seems to be LastExeption.

This code works when the back button is clicked:
B4X:
Private Sub BTGallery_Click
    CC.Show("image/*", "Bitte Bild wählen:")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    If Success = True Then
        zimvImage.SetBitmap(LoadBitmap(Dir,FileName))
        TabHost1.CurrentTab=2
    Else
        If LastException.IsInitialized Then
            xui.Msgbox2Async((LastException,"501: Programmfehler!", "OK", "", "", Main.imgError)
        Else
            xui.MsgboxAsync("Keine Dateigewählt", "501: Programmfehler!")
        End If
    End If
End Sub

Not tested with any LastException.
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Thank you, it works really.
 
Upvote 0
Top