java 从wear os键盘获取文本输入

kx1ctssn  于 5个月前  发布在  Java
关注(0)|答案(1)|浏览(60)
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    return new BaseInputConnection(this, true) {
        @Override
        public boolean finishComposingText() {
            super.finishComposingText();
            sendText(getEditable());
            getEditable().clear();
            return true;
        }

        @Override
        public boolean commitText(CharSequence text, int newCursorPosition) {
            super.commitText(text, newCursorPosition);
            Editable content = getEditable();
            sendText(content);
            content.clear();
            return true;
        }

        @Override
        public boolean deleteSurroundingText(int leftLength, int rightLength) {
            super.deleteSurroundingText(leftLength, rightLength);
        }
    }
}

字符串
我在我的自定义视图中使用了这段代码。它在Android上工作,但在wear os上不工作。在键盘上打字什么也不做。没有一个Base输入连接方法被调用。
我想像普通键盘一样输入,我不想使用远程输入。
PS:我正在使用Galaxy Watch 4(佩戴OS 4)

nbewdwxp

nbewdwxp1#

outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;

字符串
设置此选项解决了问题

相关问题