Added in API level 33

InputMethod


open class InputMethod
kotlin.Any
   ↳ android.accessibilityservice.InputMethod

This class provides input method APIs. Some public methods such as

Summary

Nested classes

This class provides the allowed list of InputConnection APIs for accessibility services.

Public constructors

Creates a new InputMethod instance for the given service, so that the accessibility service can control editing.

Public methods
InputMethod.AccessibilityInputConnection?

Retrieve the currently active InputConnection that is bound to the input method, or null if there is none.

EditorInfo?

Get the EditorInfo which describes several attributes of a text editing object that an accessibility service is communicating with (typically an EditText).

Boolean

Whether the input has started.

open Unit

Called to inform the accessibility service that text input has finished in the last editor.

open Unit
onStartInput(attribute: EditorInfo, restarting: Boolean)

Called to inform the accessibility service that text input has started in an editor.

open Unit
onUpdateSelection(oldSelStart: Int, oldSelEnd: Int, newSelStart: Int, newSelEnd: Int, candidatesStart: Int, candidatesEnd: Int)

Called when the application has reported a new selection region of the text.

Public constructors

InputMethod

Added in API level 33
InputMethod(service: AccessibilityService)

Creates a new InputMethod instance for the given service, so that the accessibility service can control editing.

Parameters
service AccessibilityService: This value cannot be null.

Public methods

getCurrentInputConnection

Added in API level 33
fun getCurrentInputConnection(): InputMethod.AccessibilityInputConnection?

Retrieve the currently active InputConnection that is bound to the input method, or null if there is none.

getCurrentInputEditorInfo

Added in API level 33
fun getCurrentInputEditorInfo(): EditorInfo?

Get the EditorInfo which describes several attributes of a text editing object that an accessibility service is communicating with (typically an EditText).

Return
EditorInfo? This value may be null.

getCurrentInputStarted

Added in API level 33
fun getCurrentInputStarted(): Boolean

Whether the input has started.

onFinishInput

Added in API level 33
open fun onFinishInput(): Unit

Called to inform the accessibility service that text input has finished in the last editor. At this point there may be a call to onStartInput(android.view.inputmethod.EditorInfo,boolean) to perform input in a new editor, or the accessibility service may be left idle. This method is not called when input restarts in the same editor.

The default implementation uses the InputConnection to clear any active composing text; you can override this (not calling the base class implementation) to perform whatever behavior you would like.

onStartInput

Added in API level 33
open fun onStartInput(
    attribute: EditorInfo,
    restarting: Boolean
): Unit

Called to inform the accessibility service that text input has started in an editor. You should use this callback to initialize the state of your input to match the state of the editor given to it.

Parameters
attribute EditorInfo: The attributes of the editor that input is starting in. This value cannot be null.
restarting Boolean: Set to true if input is restarting in the same editor such as because the application has changed the text in the editor. Otherwise will be false, indicating this is a new session with the editor.

onUpdateSelection

Added in API level 33
open fun onUpdateSelection(
    oldSelStart: Int,
    oldSelEnd: Int,
    newSelStart: Int,
    newSelEnd: Int,
    candidatesStart: Int,
    candidatesEnd: Int
): Unit

Called when the application has reported a new selection region of the text. This is called whether or not the accessibility service has requested extracted text updates, although if so it will not receive this call if the extracted text has changed as well.

Be careful about changing the text in reaction to this call with methods such as setComposingText, commitText or deleteSurroundingText. If the cursor moves as a result, this method will be called again, which may result in an infinite loop.