1

I have a barcode device that can be connected to a computer or to an android device through USB port. It scans the barcode and show the result wherever it finds a cursor, it can be an editbox, notepad, browser or whatever. What I want to do is to get data in a variable as soon it scans the barcode without showing it on the edittext.

mihirjoshi
  • 12,161
  • 7
  • 47
  • 78
  • 1
    Perhaps you could give focus to a 'hidden' `EditText` when you're about to scan a barcode? That way the result doesn't show upon being returned and you can attach a simple `TextWatcher` to the hidden `EditText` to store the result in a variable. Just not sure whether you can actually focus a view that isn't visible... – MH. Dec 20 '12 at 18:19
  • Can you provide us with the model of scanner that you are using? – MrZander Dec 20 '12 at 18:44

1 Answers1

3

Your scanner is functionally equivalent to a keyboard, so you can't scan the data directly into a variable.

However, as @MH. suggested, you can watch a text input field and grab the data once it's entered. You might be able to programmaticly set the focus on the hidden field when the user clicks a button. If that doesn't work you might be able to style the input so the user can't see the scanned data (eg make the text color the same as the background color)

Enrico
  • 10,377
  • 8
  • 44
  • 55