Android Question Know if an EditText was typed or acquired by a barcode reader

vecino

Well-Known Member
Licensed User
Longtime User
Hello, an EditText where the user types in item codes.
The EditText itself can contain codes read with a barcode reader.

Is there any way to know if the code was typed by the user or read by the barcode reader?

Thank you.
 

mc73

Well-Known Member
Licensed User
Longtime User
I know this doesn't answer your question but If it's for verification reasons, you should check the last digit which should be calculated based on previous ones.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Thank you for your help.
The reason for my question is because the user has 2 different tables, one with the "normal" codes and another table with the barcodes.
So I wanted to know to search in one table or the other.
I will probably have to search in one, and if it doesn't exist, search in the other.
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Presumably your code sets the edittext when the barcode is read. So why not set a flag?

example.

B4X:
'... Barcode read
edittext1.text = value
bValueUsingBarcode = true


' This event is called for each change in the edittext, even when the edittext is assigned above...
private Sub edittext1_TextChanged (Old As String, New As String)
    bValueUsingBarcode = false
End Sub


'Later...
if bValueUsingBarcode then
'lookup one table
else
'look up other table
end if
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Hello, thank you for your help.
I'm afraid that option is not useful, as there is no difference (as far as I know) between what is typed by the user and what is entered by the barcode reader.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Yes, exactly like that, a barcode reader reads like a keyboard. If you have a notepad open, it will type there, if you have a web browser open, it will type there... it works like a keyboard.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Is this possible?
I don't know IME_HeightChanged, can you explain a little bit how it works?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
 
Upvote 1

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Is this possible?
I don't know IME_HeightChanged, can you explain a little bit how it works?
I think (@agraham correct me if I'm wrong) that if the user has an HID barcode reader attached then the soft keyboard will not be displayed so no heightchanged event will be fired. But, if they display the soft keyboard then it will be (so you can set a "user-typed-something" flag).

This does mean that if they show the keyboard, close it then scan you will still think it was typed and not scanned. If your barcode reader supports SPP mode you could use an asyncstreams class to monitor the device for input and then send it your activity.

I've written an apps that do just that, they monitor for an SPP-mode reader input and collect everything up to a CR character, then send everything up to that CR to the current activity in a "Barcode_Reader" event.

If your reader only has an HID option, then your method of scanning both places would be best, just prioritize whichever table you expect to be most common.
 
Upvote 1

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Hello, what is HID or SPP?
HID = Human Interface Device (i.e. your program can't tell if it is a keyboard, scanner, card-reader, RFID, etc.).
SPP = Serial Port Profile. The scanner/reader works as a serial device. You connect to it, and respond to the data arrival events.

The apps that I've written generally have a class that controls the reader device, that class is instantiated and monitored in the starter service.
 
Upvote 0

epiCode

Active Member
Licensed User
?Is there a concern in searching in both tables
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
?Is there a concern in searching in both tables
It greatly depends on what he is searching and how. If it is indexed or not, how many rows/columns there is to search, what device will be doing the searching, etc.

I've been bitten enough times in my past that when coding I try to code in such a way that, whatever method I'm using, it easily scales from a few records to thousands of records.
 
Last edited:
Upvote 1

Unobtainius

Active Member
Licensed User
Longtime User
I use barcode readers all the time we set our barcode reader to append a character to the end of the scanned data. That way we know an entire barcode has been read or alternately one has been typed in. Its very easy to add a suffix character when setting up the scanner.
 
Upvote 2

vecino

Well-Known Member
Licensed User
Longtime User
Thank you very much, friends.
Your comments and advice have been very helpful.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Another method I like to use is if the data is stored in a SQLite table is to have a column called EntryType in the table that defines whether the entry is manual or scanned. So the data will be S for scanned and M manual entry. This way you have a history of the types of entries. Based on the type, it looks up the information in the proper table.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…