I am using a Barcode reader attached by USB to a Tablet
There is a strange thing happening, I am using the Barcode as a Keyboar simulation
Then I get the Keycodes by Activity_Keypress
It gets everything and my app recognizes and insert the item, however at very end of this process the app crash and in debug mode says nothing. Just close and a small dialog saying that the app closed.
There is one tablet Motorola Xoom where it works just fine, however in many others it cause the same problem. With different Android versions.
Is this the correct way to work with USB barcode readers?
I am not using control, I am getting KeyCodes using the Activity_Keypress and then consuming the event.
I have my own interface, so I dont use any EditText or similar. It recognizes it just fine, all the digits comes correct, enter at the end algo works. However at some point after everything is done the program crashes. I went step by step and everything is just fine. Since I dont have any debug information I dont know anymore what to do
I solved the problem this way: Once you've created the data string from the barcode reader in your Activity_keypress, run your code using CallSubDelayed or a timer
In Activity_keypress:
B4X:
Dim mChar As String=ConvertCode(KeyCode)
If mChar=crlf Then ' end of string from the scanner
CallSubDelayed2(Me,"RunTheCode",lastR) 'your code here
Else
lastR=lastR & mChar
End If
Return True
Dim s As String = ""
If KeyCode >= KeyCodes.KEYCODE_0 AND KeyCode <= KeyCodes.KEYCODE_9 Then
s = Chr(KeyCode + 41)
Else If KeyCode >= KeyCodes.KEYCODE_A AND KeyCode <= KeyCodes.KEYCODE_Z Then
s = Chr(KeyCode + 36)
End If
Return s
It is not about any of this..... sorry I am not getting clear to explain.
I get alll the codes just fine. But using the USB Barcode Scanner cause to crash my application.
It is not the code itself. It reads fine, I get the code, the program find the item on the database and just fine... but the program crashes from nothing, just disappear. It only works fine in an old Motorola Xoom. New tablets like Samsung Tab E just crashes
It should not happen this, my question is about what could be happening to cause this problem. Is there a better way to read from the scanner instead using keyboard emulation?
Connect to the device in USB debug mode and check the unfiltered logs. You can make the connection after the crash and then click on the Connect button in the logs tab.