Kotlin Custom Android Keyboard IME - method onUpdateCursorAnchorInfo from InputMethodService is not working

Viewed 84

I'm developing a custom android keyboard in Kotlin and I have looked at this post for how to detect cursor movement/change when the user clicks on text editor.

Here is a snippet of my code of my custom keyboard class which extends InputMethodService.

class CustomKeyboard: InputMethodService() {
    override fun onCreateInputView(): View {
        // initiated keyboard
    }

    override fun onStartInputView(info: EditorInfo?, restarting: Boolean) {
        // call onUpdateCursorAnchorInfo() whenever cursor/anchor position is changed
        this.currentInputConnection.requestCursorUpdates(InputConnection.CURSOR_UPDATE_MONITOR)
        Log.i("--------------", "onStartInputView is called")
    
    }

    override fun onUpdateCursorAnchorInfo(cursorAnchorInfo: CursorAnchorInfo) {
        Log.i("--------------", "onUpdateCursorAnchorInfo is called")
    }
}

Then I ran this app on Android Studio emulator and tested on an EditText view in the following way:

  1. I click on the EditText view on my app
  2. I input many random characters in the EditText view
  3. I click randomly on different characters in the EditText view

The system log did print out "onStartInputView is called" when I first clicked on the EditText view.

But it did not print out "onUpdateCursorAnchorInfo is called" anywhere.

What I thought would happen was that "onUpdateCursorAnchorInfo is called" would have been printed multiple times as I clicked on different parts of the EditText view.

However, when I changed to a different app and click on the text editor there, the Log did print out "onStartInputView is called" and "onUpdateCursorAnchorInfo is called" once.

But when I repeat step 1~3 on that app it did not work either

I have no idea why this behaviour occurs.

Any help would be appreciated.

1 Answers

Okay never mind somehow it works now. It must have been a bug or something.

Related