Added in API level 3

InputMethodSession

interface InputMethodSession
android.view.inputmethod.InputMethodSession

The InputMethodSession interface provides the per-client functionality of InputMethod that is safe to expose to applications.

Applications will not normally use this interface themselves, instead relying on the standard interaction provided by android.widget.TextView and android.widget.EditText.

Summary

Nested classes
abstract

Public methods
abstract Unit
appPrivateCommand(action: String!, data: Bundle!)

Process a private command sent from the application to the input method.

abstract Unit

This method is called when there is a generic motion event.

abstract Unit

This method is called when a key is pressed.

abstract Unit

This method is called when there is a track ball event.

abstract Unit

Called by a text editor that performs auto completion, to tell the input method about the completions it has available.

abstract Unit

This method is called when the application would like to stop receiving text input.

abstract Unit
toggleSoftInput(showFlags: Int, hideFlags: Int)

Toggle the soft input window.

abstract Unit
updateCursor(newCursor: Rect!)

This method is called when cursor location of the target input field has changed within its window.

abstract Unit

This method is called when the cursor and/or the character position relevant to text input is changed on the screen.

abstract Unit

Called by a text editor to report its new extracted text when its contents change.

abstract Unit
updateSelection(oldSelStart: Int, oldSelEnd: Int, newSelStart: Int, newSelEnd: Int, candidatesStart: Int, candidatesEnd: Int)

This method is called when the selection or cursor in the current target input field has changed.

abstract Unit
viewClicked(focusChanged: Boolean)

This method is called when the user tapped a text view.

Public methods

appPrivateCommand

Added in API level 3
abstract fun appPrivateCommand(
    action: String!,
    data: Bundle!
): Unit

Process a private command sent from the application to the input method. This can be used to provide domain-specific features that are only known between certain input methods and their clients.

Parameters
action String!: Name of the command to be performed. This must be a scoped name, i.e. prefixed with a package name you own, so that different developers will not create conflicting commands.
data Bundle!: Any data to include with the command.

dispatchGenericMotionEvent

Added in API level 17
abstract fun dispatchGenericMotionEvent(
    seq: Int,
    event: MotionEvent!,
    callback: InputMethodSession.EventCallback!
): Unit

This method is called when there is a generic motion event.

If the input method wants to handle this event, return true, otherwise return false and the caller (i.e. the application) will handle the event.

Parameters
event MotionEvent!: The motion event.
Return
Unit Whether the input method wants to handle this event.

dispatchKeyEvent

Added in API level 3
abstract fun dispatchKeyEvent(
    seq: Int,
    event: KeyEvent!,
    callback: InputMethodSession.EventCallback!
): Unit

This method is called when a key is pressed. When done with the event, the implementation must call back on callback with its result.

If the input method wants to handle this event, return true, otherwise return false and the caller (i.e. the application) will handle the event.

Parameters
event KeyEvent!: The key event.
Return
Unit Whether the input method wants to handle this event.

dispatchTrackballEvent

Added in API level 3
abstract fun dispatchTrackballEvent(
    seq: Int,
    event: MotionEvent!,
    callback: InputMethodSession.EventCallback!
): Unit

This method is called when there is a track ball event.

If the input method wants to handle this event, return true, otherwise return false and the caller (i.e. the application) will handle the event.

Parameters
event MotionEvent!: The motion event.
Return
Unit Whether the input method wants to handle this event.

displayCompletions

Added in API level 3
abstract fun displayCompletions(completions: Array<CompletionInfo!>!): Unit

Called by a text editor that performs auto completion, to tell the input method about the completions it has available. This can be used by the input method to display them to the user to select the text to be inserted.

Parameters
completions Array<CompletionInfo!>!: Array of text completions that are available, starting with the best. If this array is null, any existing completions will be removed.

finishInput

Added in API level 3
abstract fun finishInput(): Unit

This method is called when the application would like to stop receiving text input.

toggleSoftInput

Added in API level 3
Deprecated in API level 31
abstract fun toggleSoftInput(
    showFlags: Int,
    hideFlags: Int
): Unit

Deprecated: Starting in android.os.Build.VERSION_CODES#S the system no longer invokes this method, instead it explicitly shows or hides the IME. An InputMethodService wishing to toggle its own visibility should instead invoke android.inputmethodservice.InputMethodService#requestShowSelf or InputMethodService#requestHideSelf

Toggle the soft input window. Applications can toggle the state of the soft input window.

Parameters
showFlags Int: Value is either 0 or a combination of android.view.inputmethod.InputMethodManager#SHOW_IMPLICIT, and android.view.inputmethod.InputMethodManager#SHOW_FORCED
hideFlags Int: Value is either 0 or a combination of android.view.inputmethod.InputMethodManager#HIDE_IMPLICIT_ONLY, and android.view.inputmethod.InputMethodManager#HIDE_NOT_ALWAYS

updateCursor

Added in API level 3
abstract fun updateCursor(newCursor: Rect!): Unit

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.

Parameters
newCursor Rect!: The rectangle of the cursor currently being shown in the input field's window coordinates.

updateCursorAnchorInfo

Added in API level 21
abstract fun updateCursorAnchorInfo(cursorAnchorInfo: CursorAnchorInfo!): Unit

This method is called when the cursor and/or the character position relevant to text input is changed on the screen. This is not called by default. It will only be reported if requested by the input method.

Parameters
cursorAnchorInfo CursorAnchorInfo!: Positional information relevant to text input, such as text insertion point and composition string.

updateExtractedText

Added in API level 3
abstract fun updateExtractedText(
    token: Int,
    text: ExtractedText!
): Unit

Called by a text editor to report its new extracted text when its contents change. This will only be called if the input method calls InputConnection.getExtractedText() with the option to report updates.

Parameters
token Int: The input method supplied token for identifying its request.
text ExtractedText!: The new extracted text.

updateSelection

Added in API level 3
abstract fun updateSelection(
    oldSelStart: Int,
    oldSelEnd: Int,
    newSelStart: Int,
    newSelEnd: Int,
    candidatesStart: Int,
    candidatesEnd: Int
): Unit

This method is called when the selection or cursor in the current target input field has changed.

Parameters
oldSelStart Int: The previous text offset of the cursor selection start position.
oldSelEnd Int: The previous text offset of the cursor selection end position.
newSelStart Int: The new text offset of the cursor selection start position.
newSelEnd Int: The new text offset of the cursor selection end position.
candidatesStart Int: The text offset of the current candidate text start position.
candidatesEnd Int: The text offset of the current candidate text end position.

viewClicked

Added in API level 14
abstract fun viewClicked(focusChanged: Boolean): Unit

This method is called when the user tapped a text view. IMEs can't rely on this method being called because this was not part of the original IME protocol, so applications with custom text editing written before this method appeared will not call to inform the IME of this interaction.

Parameters
focusChanged Boolean: true if the user changed the focused view by this click.