TakePictureNow is expected to return a byte array as return value, i.e. in FocusAndTakePicture. But unfortunately it returns a Boolean value if task index does not match. This results in an exception: java.lang.ClassCastException: java.lang.Boolean cannot be cast to byte[]
Please see the following code that:
Please see the following code that:
B4X:
Public Sub TakePictureNow (MyTaskIndex As Int) As ResumableSub
'If MyTaskIndex <> TaskIndex Then Return False ' This line causes an error
If MyTaskIndex <> TaskIndex Then ' This might work
Dim empty() As Byte
Return empty
End If
Camera.AbortCaptures
Dim builder As JavaObject = Camera.CreateCaptureBuilder
CaptureSettingMap.Put("JPEG_ORIENTATION", GetHintOrientation)
SetSettingsFromMap(builder, CaptureSettingMap)
Dim CaptureRequest As Object = Camera.AddCaptureRequest(builder)
If PrintKeys Then PrintAllKeys(CaptureRequest, "Capture Request")
Wait For Camera_PictureTaken (Data() As Byte)
StartPreview(MyTaskIndex, False)
Return Data
End Sub