0

I want to show the keyboard while connecting the barcode scanner to the Android device. I know that when I connect the barcode scanner, it recognizes it as a keyboard on the Android device. However, I would like to input not only the scan but also the keyboard in the app currently under development. Therefore, I want to make the softinputkeyboard visible while connecting the barcode scanner to Android.

So, I test like this code,

private fun showKeyboard(view: View) {
    val imm = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY)
}

override fun onClick(v: View?) {
    if (v?.id == R.id.test) {
        showKeyboard(binding.test)
    }
}

However, the keyboard is not visible when the barcode scanner is connected equally. :(

And also, I try this, but it was still invisible.

class SoftKeyboard : InputMethodService() {

 override fun onEvaluateInputViewShown(): Boolean {
      super.onEvaluateInputViewShown()
      return true
 }

AndroidManifest.xml

<service android:name=".utils.SoftKeyboard"
    android:permission="android.permission.BIND_INPUT_METHOD">
    <intent-filter>
        <action android:name="android.view.InputMethod" />
    </intent-filter>
</service>
Polaris Nation
  • 831
  • 1
  • 14
  • 35

0 Answers0