I'm developing an application that lets the user scan barcodes using an external barcode scanner connected via bluetooth. The barcode scanner acts as a keyboard, i.e. Android thinks that the scanned barcodes have been typed on a keyboard.
The app is working fine as it is, as long as the screen stays on.
Once the screen turns off, I can continue scanning barcodes, but the scanned text doesn't reach the app anymore, but rather invokes actions on the lock screen.
Is there a way to allow input from an external keyboard to the app although the screen has been turned off?
Alternatively I will have to force the screen to stay turned on, but this isn't bullet-proof, as the user might accidentally lock the screen.
UPDATE
I've made a small step in the right direction by using:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
This will show the app without the (non-secure) lock screen when a new input from the keyboard is processed. Unfortunately, the first letter is missing. This has to be caused by the first letter waking the screen and the rest of the input actually reaching the EditText
.
This works for me in a similar situation. Just keep screen on while your application in foreground.
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
);
if you are only losing the first number, then you can... recover that using the Check Digit.
I know it is a hack but it should solve this problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With