Android Question Take multiple photos with MediaChooser library

John Naylor

Active Member
Licensed User
Longtime User
The MediaChooser library is almost exactly what I need in my app however I want my users to be able to take multiple photos before going back to my app, not just one.

I played about and added the following

B4X:
Sub CaptureMultipleImages As ResumableSub
    Dim photos As List
    photos.Initialize
    Do While True
        Dim i As Intent
        i.Initialize("android.media.action.IMAGE_CAPTURE", "")
        Dim tempImageFile As String = GetTempFile
        Dim u As Object = FileProvider1.GetFileUri(tempImageFile)
        i.PutExtra("output", u) ' Save each image to the same location or new temp file
        
        Try
            Wait For (StartForegroundService) Complete (unused As Boolean)
            StartActivityForResult(i)
            Wait For ion_Event (MethodName As String, Args() As Object)
            If -1 = Args(0) Then
                If File.Exists(TempFolder, tempImageFile) Then
                    photos.Add(CreateMediaChooserResult(True, TempFolder, tempImageFile, DetectImageMime(TempFolder, tempImageFile)))
                End If
            Else
                Exit ' Exit the loop if the user cancels or something goes wrong
            End If
        Catch
            Log(LastException)
            Exit ' Exit on exception
        End Try
    Loop
    
    Return photos ' Return a list of all the captured photos
End Sub

Which works quite well - I can take multiple photos and then end the process by hitting the Back button. I then get a list of MediaChooserResult types containing the relevant data.

My only issues are that after each photo is taken my app comes back to the foreground briefly as opposed to the camera intent staying on screen. I can live with it but would prefer it to not flash my app up if possible. I also have to click the tick in the photo intent to accept the photo. I'd like to be able to fire off multiple photos without any other intervention than pressing the main 'Take Picture' button.

Is this something I'm stuck with? Is there a way of not having to click the tick button after taking a photo (on Lenovo tablet it's a tick, it's an OK/ Cancel option on a Samsung S22)? Certainly not issues that will stop me using the library as it is fantastically easy to use but if you don't ask you don't get ? I fully appreciate this is all likely down to the device camera app but maybe.....

Attached is the MCExample app adjusted with my additional code to demonstrate my issue - Just press the Camera button and take a few shots.

TIA
 

Attachments

  • MCExampleMultiplePhotos.zip
    189.6 KB · Views: 32
Top