Android Question Barcode Detector Vision


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.

Private Sub CreateDetector (Codes As List)
    Dim ctxt As JavaObject
    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
    Dim format As Int
    For Each formatName As String In Codes
        format = Bit.Or(format, barcodeStatic.GetField(formatName))
    builder.RunMethod("setBarcodeFormats", Array(format))
        detector = builder.RunMethod("build", Null)
        Dim operational As Boolean = detector.RunMethod("isOperational", Null)
        Log("Is barcode detector operational: " & operational)

        BarCodeOperational = operational
        BarCodeOperational = False
    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;
Cannot get methods of class:$Builder, disabling cache.
Error occurred on line: 130 (OperationsScanner)
java.lang.RuntimeException: Method: setImageData not found in:$Builder

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
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="29"/>

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.


Well-Known Member
Licensed User
Longtime User
See this is why I keep backup copies of everything before I "upgrade". Thats turned me into a data hoarder with crap that goes back to the 90s, but I digress...

In the (supposed to be rare, but ends up not so rare) situations where I need to support older devices, I can refer back to older installs, with the older SDK and SDK manager.

I still have a fleet of digital signage controllers running Android 4, and they still come brand new out of china with that same Android 4 platform so I dont have any choice. At this point they are starting to have trouble with SSL connections, so I have to keep the content management servers running older TLS versions.

Moral of the story is, if you have to support a fleet of older mission-critical devices with no guarantees of backwards-compatibility on upgrades, Then setup a specific VM or a specific development environment to support THAT platform. Deprecation and changes happen about as often as people changing clothes, and it drives me batty!

This kinda stuff is the fuel that has slowly turned me anti-progressivist. As much as technology marches on, sometimes i disagree on how/why it does. But, what do I know? By my logic, we would still be stuck in the MS-DOS days, or even mainframe days! so sometimes I don't even understand myself. lol.... I guess how I feel is, eventually we have to move on, but the pace is too rapid for me to keep up with and adjust to and it angers me... Anyways, yet again, I digress...
Last edited:
Upvote 0


The latest version is here:
The minimum version for Google SDK is Android 4.1.

The external dependencies, which are unique to this feature, are explained here:

The sample is not working
I think the SDK is moved to other place:
Upvote 0


I downloaded the sample project.
But when runing it shows the toast message that says "Failed to create detector"
My phone is Xiaomi Note 8 Pro , Android ver 11.

The external dependencies, which are unique to this feature, are explained here:

I tried to open this url , but it says that: Mobile Vision has moved to ML Kit
My phone did not download the requird external dependencies automatically after one day of runing this sample project so I think some codes may need to be changed to address ML Kit
Last edited:
Upvote 0