Home > Net >  How to open Android Wear keyboard programmatically?
How to open Android Wear keyboard programmatically?

Time:10-12

So I have a question of how to open the keyboard that shows when the user clicks in an EditText.

enter image description here

I already found a way to open the speech recognizer using:

        val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
        intent.putExtra(
            RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
        )
        startActivityForResult(intent, SPEECH_REQUEST_CODE)

But now I want to open the simple keyboard.

Already tried to create a working using a simple EditText and call requestFocus() performClick() to show the keyboard but without success.

CodePudding user response:

Okay, so after a lot of digging and experimenting other apps while debugging, I found a way to open the keyboard. Couldn't find a way to customize it (inputType, imeActionType, etc) but atleast it opens.

To show the keyboard.

val intent = Intent("com.google.android.wearable.action.LAUNCH_KEYBOARD")
startActivityForResult(intent, REQUEST_CODE_KEYBOARD)

To get the value from the result that the user inserted, or not.

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (resultCode == RESULT_OK) {
        when (requestCode) {
            REQUEST_CODE_KEYBOARD -> {
                val resultText: String = data?.extras?.getString("result_text") ?: ""
                sendComment(resultText)
            }
        }
    }
}
  • Related