0

I have android barcode scanner with physical keyboard. Is possible on app startup inside onCreate() method detect if some key is pressed and hold down? The idea is that if app is starting and key X is down then load another configuration. Like safe mode for firefox when shift key is pressed when firefox is starting.

Edit. Use case:

  • App is starting ( onCreate ).

  • get default activity from settings. Ex myAct="actA.java"

  • if key 1 is down then myAct="defaultActivity.java"

  • startActivityForResult(myAct)

Guntis
  • 496
  • 1
  • 5
  • 19

1 Answers1

0

A little late, but perhaps some sort of splash screen as your first activity, not only will this give the user a chance to press a key (you have no guarantee of the context if you try to detect it before your app starts), but in Activity you can simply override onKeyDown. eg.

  • SplashActivityLoads and displays for 5 seconds
  • Using override fun onKeyDown(); detect which key has been pressed and store in a local variable
  • After you SplashActivity 5 seconds (or whatever) is up, use your stored variable to decide which Activity to launch, if(keyCode == KeyEvent.KEYCODE_X) actA.java else defaultActivity.java
Terry W
  • 203
  • 3
  • 9