简体   繁体   English

如何以编程方式打开 Android Wear 键盘?

[英]How to open Android Wear keyboard programmatically?

So I have a question of how to open the keyboard that shows when the user clicks in an EditText.所以我有一个问题,如何打开当用户单击 EditText 时显示的键盘。

在此处输入图像描述

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.已经尝试使用简单的 EditText 创建工作并调用requestFocus() performClick()来显示键盘但没有成功。

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.找不到自定义它的方法(inputType、imeActionType 等),但至少它会打开。

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)
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM