I'm working in an Android app that must use a RFID tag reader. I'm using this reader as an extra device connected in my microUSB with an OTG wire. Android is detecting this device as an input keyboard. I would like to know if I can programatically detect when a user does an input with this reader. So basically I must differenciate the input from my softkeyboard or this reader. I searched a lot but I can't find a solution any help would be so appreciated. Thank you very much.
Asked
Active
Viewed 3,522 times
2
-
You can try http://developer.android.com/reference/android/inputmethodservice/InputMethodService.html onStartCandidatesView(android.view.inputmethod.EditorInfo, boolean) – Waqar Khan Apr 21 '15 at 10:24
-
I read that function but I can't understand its use – acostela Apr 21 '15 at 10:28
-
OK. What do you exactly want to do? – Waqar Khan Apr 21 '15 at 10:32
-
I want to difference in an editText if the numbers entered i.e. "123456" are inserted by the softkeyboard or my device. I'm looking for some info about the function onStartCandidatesView() but I can't find anything so conclusive – acostela Apr 21 '15 at 10:34
-
You can try using [OnKeyListener](http://developer.android.com/reference/android/view/View.OnKeyListener.html) if the keydown event is fired means input is from softinput else from hardinput – Waqar Khan Apr 21 '15 at 10:45
-
[Here](http://www.programcreek.com/java-api-examples/index.php?api=android.view.View.OnKeyListener) is a sample code to use that. – Waqar Khan Apr 21 '15 at 10:47
-
Thank you very much I will try it. If it's useful i will tell you and you post the answer ;) thank – acostela Apr 21 '15 at 10:49
-
You are welcome :) Let me know if you have some problem. – Waqar Khan Apr 21 '15 at 10:51
-
Android automatically makes hardware input the default input, so if your RFID reader is connected, it will always be used for input unless the user manually switches from hardware input to software input. – Sbonelo Apr 21 '15 at 11:02
-
@SboneloMbhamali now I have both keyboards working at the same time so I think that's not a problem. I only should detect when the input is done with the soft or the hard keyboard – acostela Apr 21 '15 at 11:04
2 Answers
1
yourEditText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
return false;
}
});
This will detect if your editText is being editted with a hardware keyboard.
As stated here this is only useful for hardware keyboard, so in your case if this interface is not called, that means the editText input should come from the software keyboard.

Sbonelo
- 664
- 1
- 9
- 25
-
That's not 100% true. Its only guaranteed to work for a hardware keyboard. It may or may not work for a software keyboard, depending on whether or not the software keyboard is sending hardware keyboard commands to Android (which most don't except under odd circumstances, but there is a command to do so). – Gabe Sechan Apr 21 '15 at 20:17
-
This is an okay solution except that there's no way to find out before the user actually makes an input... – funct7 Oct 11 '20 at 00:54
0
In kotlin, I am using KeyEvent to determine whether input is from external RFID tag reader. When I don't want to allow inserting values to edit_text from RFID reader I am using this:
edit_text.setOnKeyListener { _, _, event -> !event.device.isVirtual }
also see docs and try to use it in relation to your problem

Kamil Z
- 181
- 12