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
.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
and add this permission in manifest<uses-permission android:name="android.permission.WAKE_LOCK" />
. you are done. – Gardy