I need help from this group. I am using ZxingBarcodeScanner v1.00 library to create a camera scanner to scan QR codes.
I follow the original sample to create the barcode camera. All ran well but after SDK v28 (or earlier) the app hung as below
- scan barcode ok for a while
- suddenly hang during scanning
- when restart app and scan again, camera show black screen, same when start Android camera
- only solved by wait for long time or reboot Android phone
That happened in Samsung, Huawei and Xiaomi (9T pro). Attached is the latest hang screen.
Part of the code as following
The manifest as below
I follow the original sample to create the barcode camera. All ran well but after SDK v28 (or earlier) the app hung as below
- scan barcode ok for a while
- suddenly hang during scanning
- when restart app and scan again, camera show black screen, same when start Android camera
- only solved by wait for long time or reboot Android phone
That happened in Samsung, Huawei and Xiaomi (9T pro). Attached is the latest hang screen.
Part of the code as following
B4X:
Sub Globals
..
Private zx1_cont As ZxingBarcodeScanner
...
Sub Activity_Create(FirstTime As Boolean)
...
scanbarcode_init_cont
...
Sub Activity_Resume
If pnl_scan.Visible Then
zx1_cont.Visible = True
zx1_cont.startScanner
End If
...
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If pnl_scan.Visible Then
zx1_cont.Visible = False
zx1_cont.stopScanner
End If
...
End Sub
Sub scanbarcode_init_cont
zx1_cont.LaserColor = Colors.Red
zx1_cont.MaskColor = Colors.ARGB(100, 0, 0, 100)
zx1_cont.BorderColor = Colors.Blue
zx1_cont.BorderStrokeWidth = 5
zx1_cont.BorderLineLength = 40
zx1_cont.Visible = False
End Sub
Sub scanbarcode_pause_cont
' causing hang ?
'zx1_cont.Visible = False
'zx1_cont.stopScanner
End Sub
Sub scanbarcode_start_cont
pnl_scan.Visible = True
pnl_scan.BringToFront
chk_cont.Checked = gScanCont
zx1_cont.Visible = True
zx1_cont.startScanner
End Sub
Sub scanbarcode_stop_cont
zx1_cont.Visible = False
zx1_cont.stopScanner
pnl_scan.Visible = False
lv_barcode_cont.Clear
lbl_cnt_cont.Text = "0"
btn_getbarcode_cont.Text = "Get Barcode"
End Sub
Sub scanbarcode_flash_cont
zx1_cont.toggleFlash
End Sub
Sub zx1_cont_scan_result (scantext As String, scanformat As String)
If gScanCont = False Then
btn_getbarcode_cont.Text = scantext
btn_getbarcode_cont_Click
Else
Dim lcnt As Int
Dim fdup As Boolean
lcnt = 0
fdup = False
Do While lcnt < lv_barcode_cont.Size
If lv_barcode_cont.GetItem(lcnt) = scantext Then
fdup = True
Exit
End If
lcnt = lcnt + 1
Loop
If fdup = False Then
lv_barcode_cont.AddSingleLine(scantext)
lv_barcode_cont.SetSelection(lv_barcode_cont.Size)
lbl_cnt_cont.Text = lv_barcode_cont.Size
btn_getbarcode_cont.TextColor = Colors.Black
btn_getbarcode_cont.Text = scantext
Else
btn_getbarcode_cont.TextColor = Colors.Red
End If
End If
End Sub
The manifest as below
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="30"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
AddManifestText(<uses-feature android:name="android.hardware.telephony" android:required="true" />)
AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="false" />) ' to avoid xiaomi cam crash
AddManifestText(<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.flash" android:required="false" />)
Last edited: