2

Is it possible to somehow catch the text input event if the application does not display EditText (the text box), and there is not soft-keyboard?

OS: Android 4.1.2

P.S. Let me explain why this is necessary: there is a device - Motorola TC55 - (data collection terminal, smartphone on Android 4.1.2 with barcode reader (laser)), which on its left side has a button for scanning.

After pressing it the laser scanner is turned on, reads the barcode and after the reading of the barcode symbols that are read are programmatically "pressed".

vladon
  • 8,158
  • 2
  • 47
  • 91
  • Did you try overriding [`onKeyDown()` in your activity](http://developer.android.com/reference/android/app/Activity.html#onKeyDown%28int,%20android.view.KeyEvent%29)? – CommonsWare Aug 28 '14 at 13:59

2 Answers2

1

have you tried to override the onKeyDown method ?

 @Override 
public boolean onKeyDown(int keyCode, KeyEvent event)  {
    Log.d("MyApp", "key downed : " + keyCode);
    if ( keyCode == KeyEvent.KEYCODE_SCANNER /* HERE AN OBSVIOUSLY FALSE CONSTANT*/ ) {

       // perform your desired action here 

       // return 'true' to prevent further propagation of the key event 
       return true; 
    } 

    // let the system handle all other key events 
    return super.onKeyDown(keyCode, event);
} 

now you just have to track and find the right keycode in this list : http://developer.android.com/reference/android/view/KeyEvent.html

see this response for more details : https://stackoverflow.com/a/19215087/1802663

Community
  • 1
  • 1
Apollo
  • 196
  • 1
  • 9
1

A different solution should be to leverage the Intent made available by these devices when they read a barcode.

You can find more information in the developer documentation for the TC55, it's simply to configure the device so that it send an Intent with the barcode data to your application.

This configuration can be exported and reused on different device. another option is to have your application setting up the configuration programmatically using TC55's Profile API. In this way you can fine tune the barcode decoder for your use case.

Using DataCapture Intents it's much cleaner that using the simulated keyboard entry.

pfmaggi
  • 6,116
  • 22
  • 43