Android Question Intent Based Camera - Taking photo with confirm screen

rleiman

Well-Known Member
Licensed User
Greetings,

I'm experimenting with the intent based camera by Erel and would like to alter this code in TakePicture so the confirmation screen with "Ok" and "Retry" is not displayed so execution goes directly to ion_Event.

Truly,
Emad

B4X:
Sub TakePicture
    Dim i As Intent
    i.Initialize("android.media.action.IMAGE_CAPTURE", "")
    File.Delete(imageFolder, tempImageFile)
    Dim p As Phone
    Dim u As Object
    If p.SdkVersion < 24 Then
        Dim uri As Uri
        uri.Parse("file://" & File.Combine(imageFolder, tempImageFile))
        u = uri
    Else
        u = CreateFileProviderUri(imageFolder, tempImageFile)
    End If
    i.PutExtra("output", u) 'the image will be saved to this path
    Try
        StartActivityForResult(i)
    Catch
        ToastMessageShow("Camera is not available.", True)
        Log(LastException)
    End Try
End Sub

'result arrives here
Sub ion_Event (MethodName As String, Args() As Object) As Object
    If Args(0) = -1 Then
        Try
            Dim in As Intent = Args(1)
            If File.Exists(imageFolder, tempImageFile) Then
                lastPicture = LoadBitmapSample(imageFolder, tempImageFile, ImageView1.Width, ImageView1.Height)
                ImageView1.Bitmap = lastPicture
                
                Dim Out As OutputStream
                Out = File.OpenOutput(GetExternalStoragePublicDirectory("DCIM") & "/Camera", "Emad.jpg", False)
                
                lastPicture.WriteToStream(Out, 100, "JPEG")
                Out.Close

            Else If in.HasExtra("data") Then 'try to get thumbnail instead
                Dim jo As JavaObject = in
                lastPicture = jo.RunMethodJO("getExtras", Null).RunMethod("get", Array("data"))
            End If
        Catch
            Log(LastException)
        End Try
    End If
    If lastPicture.IsInitialized Then ImageView1.Bitmap = lastPicture
    Return Null
End Sub
 
Top