Android device: Problems with external code scanning gun and system soft keyboard

Android device: Problems with external code scanning gun and system soft keyboard

Q&A

Q: The code scanner will automatically activate the system soft keyboard after scanning the code.
A: The code scanner is equivalent to an external keyboard. Android devices with different external keyboards behave differently. Generally, we expect the external keyboard and the system keyboard to be mutually exclusive. See if the manufacturer has done adaptation processing in the Framework. If you don’t want to pop up the system soft keyboard, you can disable the Activity soft keyboard:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

Unban:

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

Q: After the code scanning gun has scanned the code, the soft keyboard will automatically pop up, and the EditText display content is missing or the code monitors the code scanning event. The monitored KeyEvent.getKeyCode is KeyEvent.KEYCODE_ENTER
A: Because the code scanning gun conflicts with the system soft keyboard, some The data is intercepted by the system soft keyboard. Disabling it can solve this problem.

Q: EditText loses focus after the code is scanned by the scanner.
A: The scanned code usually has a carriage return at the end, which causes EditText to lose focus. You can configure EditText with the following next series of attributes, so that its next focus still points to itself:

<EditText
            android:id="@+id/edit_scan_code"
            android:layout_width="800px"
            android:layout_height="200px"
            android:textSize="50px"
            android:nextFocusDown="@id/edit_scan_code"
            android:nextFocusForward="@id/edit_scan_code"
            android:nextFocusLeft="@id/edit_scan_code"
            android:nextFocusRight="@id/edit_scan_code"
            android:nextFocusUp="@id/edit_scan_code"
            android:nextClusterForward="@id/edit_scan_code"/>

Guess you like

Origin blog.csdn.net/mxiaomi/article/details/114059507