I am developing an application that allows you to scan user barcodes using an external barcode scanner connected via bluetooth. The barcode scanner works like a keyboard, i.e. Android believes that the scanned barcodes were entered on the keyboard.
The application works fine while it remains.
As soon as the screen turns off, I can continue to scan barcodes, but the scanned text no longer reaches the application, but rather causes actions on the lock screen.
Is there a way to allow input from an external keyboard into the application, although the screen is off?
Alternatively, I will have to force the screen to remain on, but this is not bulletproof, since the user may accidentally lock the screen.
UPDATE
I took a small step in the right direction using:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
This will show the application without a lock screen (insecure) when processing new keyboard input. Unfortunately, the first letter is missing. This should be because the first letter wakes up the screen and the rest of the input actually reaches the value of EditText .
source share