we are implementing custom input method service and we are interested in receiving cursor update events. The documentation of InputMethodSession's updateCursor() says: "This method is called when cursor location of the target input field has changed within its window. This is not normally called, but will only be reported if requested by the input method."
How the input method can request this event?
Thanks in advance,
Andriy
It looks like this is unimplemented. In the
TextView
implementation, callingupdateCursor
is conditional onInputMethodManager.isWatchingCursor
, which is helpfully defined as follows:Luckily, you can detect cursor movements using
onUpdateSelection
, although they will be given to you as a logical position within the text rather than a Rect.From API level 21 (Lollipop) there is a way to do it:
Override
onUpdateCursorAnchorInfo(CursorAnchorInfo cursorAnchorInfo)
and call
inputConnection.requestCursorUpdates(int cursorUpdateMode)
after you got the inputConnection.
The
onUpdateCursorAnchorInfo
will be called every time the cursor's position has changed.