I've got this mobile device, it has a barcode reader and SCAN button. So, I've got no EditTexts on my mainActivity, but I want to get an event, when barcode scanning ends, and reŃeive barcode value in event's handler.
Kinda way to do this is to place an edittext to the activity and bind a textwatcher to it, and when edittext's value changes, read it's value. But I have to do this on a simple screen without any inputs.
The SCAN button doesn't place any value, it seems to be starting another component, that reads a barcode and places value into an input field.
So, how do I get this without any inputs? Thanks in advance.
Tried having an invisible EditText field?
<EditText
...
android:visibility="invisible">
Have you used zxing library for barcode scan? If yes than you will get event in handleDecodeInternally function in CaptureActivity because that function called when barcode scanning ends. Also you can set your EditText in capture.xml and set value in handleDecodeInternally function.
Related
I am writing an app for a custom android device that includs a barcode scanner. Inside my app is a WebView.
Out of the box, the scanner populates html fields inside the webview without calling any library methods.
I can see the text in Android Studio's profiler. I have attached pictures of the event. For testing, I created a barcode encoded with the text "Your Text".
My problem is, I need to capture this event or replicate it, but I don't know what type of event it is. I originally thought the text was part of the Key Event, but the String is not there. It seems like it is another key press event. Is there a way to capture or replicate this mysterious event?
it might be the key-code assigned to the scanner's trigger button (just press and hold it for a second)... when the duration of the key-event changes, this should be proven. KEYCODE_BUTTON_R1 is 103:
On a game controller, the R1 button should be either the button labeled R1 (or R) or the top right trigger button.
there might be configuration bar-codes available, to enable/disable/change that key-code.
Since I'm using scanner, after scanning the barcode into edittext I need to get text from the edittext automatically and check the record for that barcode from the local database.
I know that there is addTextChangedListener for getting the text from the edittext automatically. But there are issues with that like it is checking each character of barcode when scanned instead of checking the barcode string in the local database.
You may use Handler and its methods
postDelayed(Runnable r, long delayMillis) and
removeCallbacks(Runnable r).
In your TextWatcher invoke removeCallbacks(...) in order to remove any previous Runnable and invoke postDelayed(...) with a little delay and a Runnable that will check the barcode string.
So you may accomplish your search in the database in several milliseconds after the last digit was sent to your EditText.
Also your scanner may send a special symbol at the end of a barcode. So read its documentation. Probably you don't need Handler, but you need to wait for that special symbol
I have two challenges in my android program whcih are listed below , Kindly help me.
Suppose I start a thread A in MainActivity , and based on whether a certain condition
is met in thread A , the whole application must be closed. ( as finish() is available only in Activity and not accessible from a thread )
2.In MainActivity I have an EditText. Every letter i press is setup to transfer over bluetooth Socket to reach PC over bluetooth StreamCOnnection.
Hence , I need to get every letter (single character) that I type in the EditText, stored in a char variable. (It should also take into account the backspace button which means that no letter was typed).
As and when user types a letter in EditText , a char variable (single letter) is initialized in MainActivity and a running thread "A" will fetch and send value of the char variable to socket outputstream and clear the char variable so that newly entered letter could be stored for subsequent socket streams sending.
Hence my question for the point 2 is , How to fetch the last typed character of an EditBox taking into consideration backspace key to be ignored.
I Googled lot and also referred similar posts (Link1) & Link2, but I couldn't successfully implement it.
( PS: I'm Sorry that I have written detailed, instead of pasting Snippets as my program is a bit big and could confuse what my correct question is)
1) finish() is a function on the Activity object. If the thread is a subclass of the activity, it can fall it. If the Thread has a reference to the Activity, it can call activityReference.finish(). Finish() is the only way to end an activity programmatically.
2)Use a TextWatcher and add it to the EditText. That will tell you whenever a character is typed. You can figure out what the new data is and process it.
My suggestions would be:
1) Use a Handler to make a callback to the UI thread if the condition is met. From there, you can call the finish() method.
2) I would implement on onKeyListener for the Edittext. In that listener, you can listen for any key press you want (character or other).
Hope that helps.
I am developing a sample for searching functionality.
I have used onSearchRequested() and on calling it, I get an edit box in which I can enter
the search parameter.
What I would like to do is, I want to capture the text entered in the edit box as I would like to send it to another activity.
Generally for an editText that is defined by us , we can access it using its 'id'.
But, since in the case of onSearchRequested(), the editText is creted automatically , so how can I access and capture the text typed in it.
Have a look at the documentation regarding creating a search interface. Part of the documentation is an example on how to set up a SearchableActivity that is called with the query entered by the user and that should do the searching and showing the results. I guess this is exactly what you want.
Is it possible to have the barcode scanner (zxing for example) called instead of the keyboard in a webview? So, just to be clear, when I tap in a text box inside my webview I'd like to override the keyboard call and have the barcode scanner open instead as an input to the text field. Is this feasible?
Yes its possible , i implemented this softkeyboard which does the job.
'Long press' shift key and you can scan a code which adds to the text field
which has focus.
http://www.androidbroadcast.com/en/softkeyboard/index.html
Barcodescanner Keyboard lets you do exactly this. It is definitely possible.
it possible go to http://www.tec-it.com/en/software/android/barcode-keyboard/barcodekeyboard-overview/Default.aspx
download barcode keyboard demo version and enjoy....
Not in any kind of standard fashion: you could plug a custom JavaScript handler that listened for focus messages from the specific text input (identified perhaps by id?) and then use the InputMethodManager to hide the input method and launch your barcode reader. When the barcode reader returns with content you could then use the same JavaScript handler to insert the result into the text input field.
This isn't exactly what you are asking for but might work: You could modify the ZXing bar code scanning library to dispatch key events for each character in the scanned bar code. I assume these key events would be interpreted by the text field. You can program the bar code scanner to append a carriage return or whatever to accept the data into the text field as if someone had hit the enter key. You could put a border around your layout and turn it red or something to indicate to the user that it will accept typed in data or a bar code scan.
It is not possible -- at least, there's nothing in Android or ZXing that lets you do this directly. But you can certainly write your own Input Method that does such a thing, if you're willing to put in the work. ZXing is open source and there have been some topics about it in the discussion group.