Android Question Problem with soft keyboard when using bar code scanner

Danamo

Member
Licensed User
I'm creating an inventory app where, for each inventory item record, I use a bluetooth bar code scanner to scan a bar code into an edit text box. Then, using the soft keyboard, I need to type a description and some other info into various other edit text boxes to complete the record and add it to my database.

The scanner is paired and works fine for entering the scanned bar code into the edit text box, but then I can't get the soft keyboard to come up on the screen. If I run the app without the scanner I can use the soft keyboard to type the info into all the fields, but if I use the scanner I lose the soft keyboard. It seems like I can only use either the scanner or the soft keyboard, but not both in the same app?

I know the scanner is effectively a keyboard entry device. Am I just making some dumb beginners mistake here, or is Android unable to handle both input devices in the same activity?

Any suggestions on what I'm doing wrong, or what I need to do to make this this darn thing work? :confused:
Not asking anyone to write code for me, but if you could just steer me in the right direction I might be able to keep what few gray hairs I still have remaining!
 

DonManfred

Expert
Licensed User
Longtime User
Start with uploading a small example which shows the problem.

What did you tried to ge the softkeyboard open on the other Edittextfields?

Hard to help if we do not know what code you are using
 
Upvote 0

Dey

Active Member
Licensed User
Longtime User
Hi,
you have to go to the language settings and id and select the soft key again
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I really didn't search if both keyboards (scanner and soft) can be switched to each other in an easy way, which would be the best I think.

So, one way you can deal with it is to NOT use your barcode scanner in HID mode. This way, the normal keyboard will open, but then you have to programmatically get the scans from your device.

Anothe way, which I personally used in a very similar case, is to build a small custom keyboard on screen, so that user can enter the needed information.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Upvote 0

Danamo

Member
Licensed User
Start with uploading a small example which shows the problem.

What did you tried to ge the softkeyboard open on the other Edittextfields?

Hard to help if we do not know what code you are using

I'm not using any code to open or close the soft keyboard.

Here is code to demonstrate the issue...

B4X:
Sub Globals
    Private Button1 As Button
    Private EditText1 As EditText
    Private EditText2 As EditText
    Private EditText3 As EditText
End Sub

Sub Activity_Resume
    EditText1.RequestFocus
End Sub

Sub EditText1_EnterPressed
    Log("Enter Pressed in EditText1")
    EditText2.RequestFocus
End Sub

Sub EditText2_EnterPressed
    Log("Enter Pressed in EditText2")
    EditText3.RequestFocus
End Sub

Sub EditText3_EnterPressed
    Log("Enter Pressed in EditText3")
End Sub

Sub Button1_Click
    Log("EditText1.Text = " & EditText1.Text)
    Log("EditText2.Text = " & EditText2.Text)
    Log("EditText3.Text = " & EditText3.Text)
End Sub

When NOT using the bar code scanner, the soft keyboard appears with focus on EditText1. I type a bar code and press Return on the soft keyboard. Focus moves to EditText2 and I still have the soft keyboard on the screen. I type in some text and press Return on the soft keyboard. Focus moves to EditText3 and I still have the soft keyboard on the screen. I type in some text and press Return on the soft keyboard. The soft keyboard disappears from the screen. I press Button1 and the Logs shows the results.

Logger connected to: TCL Alcatel_4060A
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **

Enter Pressed in EditText1
Enter Pressed in EditText2
Enter Pressed in EditText3
EditText1.Text = 12345
EditText2.Text = test
EditText3.Text = test2

When I DO USE the bar code scanner, the soft keyboard appears with focus on EditText1. Instead of typing on the soft keyboard, I scan a bar code. The soft keyboard disappears and focus moves to EditText2. Having used the scanner, I can no longer get the soft keyboard back up on the screen. Tapping the other EditText fields won't bring the soft keyboard back, either.

I have tried using IME with ShowKeyboard(EditText) as in...

Sub EditText2_FocusChanged (HasFocus As Boolean)
If HasFocus = True Then
IME.ShowKeyboard(EditText2)
End If
End Sub

but the results are still the same: the soft keyboard will not show again after having used the bar code scanner for entry into any of the EditText fields.

I think that the SPP mode example suggested by KMatle is the direction I need to go. I'll have to treat the data from the scanner as a serial stream and handle it in my code accordingly rather than letting Android handle it as a keyboard event.
 
Upvote 0

Danamo

Member
Licensed User
See my example here to use it in SPP mode: https://www.b4x.com/android/forum/threads/use-a-handheld-bluetooth-scanner-via-spp-mode.83490/

At the first sight it looks complicated but believe me, it's easier:

- scanned data is received in s asub so you can decide where to put it (edittext, label, etc.)
- you don't need any logic to handle the keyboard or take care that the edittext has focus, etc.

Thanks! I believe your approach is how I'll have to do it... treat the data from the scanner as a serial stream and handle it accordingly in my code, rather than letting Android handle it as a keyboard event. It's not really too complicated - even for me :confused: - since your explanation and example are quite good.
 
Upvote 0
Top