Hi, on android 4.2.2 i get from builder isOperation = False. This code was working fine before on this mobile phone. It is hard for me to pin point when it stoped working but could be when changing to newer targetSDK (after updating to new version of b4a and a lot of maven errors). Apperently does not work also in Android 7.0, on 8.0 and 10.0 it works without problems.
It does not go into Catch, it just returnes false in method isOperational (detector.RunMethod)
It also sometimes crashes with following error, since it gets to this code when it will try to analyze frame, i think that sometimes would even receive isOperational = true, because Camera1_Preview has check if BarCodeOperationl = True on start of sub;
HEre is what i have in manifest
Also additional jars
This was working for years, so must be some "recent" change (by recent could be anywhere in last couple of months).
I am not sure if any code posted would help, more or less everything is the same as Erel example for barcode scanner. Except changes made few years ago to support landscape orientation. But all was fine and working on old phones before.
B4X:
Private Sub CreateDetector (Codes As List)
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim builder As JavaObject
builder.InitializeNewInstance("com/google/android/gms/vision/barcode/BarcodeDetector.Builder".Replace("/", "."), Array(ctxt))
Dim barcodeClass As String = "com/google/android/gms/vision/barcode/Barcode".Replace("/", ".")
Dim barcodeStatic As JavaObject
barcodeStatic.InitializeStatic(barcodeClass)
Dim format As Int
For Each formatName As String In Codes
format = Bit.Or(format, barcodeStatic.GetField(formatName))
Next
builder.RunMethod("setBarcodeFormats", Array(format))
Try
detector = builder.RunMethod("build", Null)
Dim operational As Boolean = detector.RunMethod("isOperational", Null)
Log("Is barcode detector operational: " & operational)
BarCodeOperational = operational
Catch
BarCodeOperational = False
Log(LastException)
End Try
End Sub
It does not go into Catch, it just returnes false in method isOperational (detector.RunMethod)
It also sometimes crashes with following error, since it gets to this code when it will try to analyze frame, i think that sometimes would even receive isOperational = true, because Camera1_Preview has check if BarCodeOperationl = True on start of sub;
B4X:
Cannot get methods of class: com.google.android.gms.vision.Frame$Builder, disabling cache.
Error occurred on line: 130 (OperationsScanner)
java.lang.RuntimeException: Method: setImageData not found in: com.google.android.gms.vision.Frame$Builder
B4X:
Sub Camera1_Preview (data() As Byte)
If BarCodeOperational And BarCodePause = False Then
...
Dim frameBuilder As JavaObject
Dim bb As JavaObject
bb = bb.InitializeStatic("java.nio.ByteBuffer").RunMethod("wrap", Array(data))
frameBuilder.InitializeNewInstance("com/google/android/gms/vision/Frame.Builder".Replace("/", "."), Null)
Dim cs As CameraSize = camEx.GetPreviewSize
frameBuilder.RunMethod("setImageData", Array(bb, cs.Width, cs.Height, 842094169))
HEre is what i have in manifest
B4X:
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="29"/>
Also additional jars
B4X:
#AdditionalJar: com.google.android.gms:play-services-vision
#AdditionalJar: com.google.android.gms:play-services-base
This was working for years, so must be some "recent" change (by recent could be anywhere in last couple of months).
I am not sure if any code posted would help, more or less everything is the same as Erel example for barcode scanner. Except changes made few years ago to support landscape orientation. But all was fine and working on old phones before.