InputMethod

public class InputMethod
extends Object

java.lang.Object
   ↳ android.accessibilityservice.InputMethod


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

Summary

Nested classes

class InputMethod.AccessibilityInputConnection

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

Public constructors

InputMethod(AccessibilityService service)

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

Public methods

final InputMethod.AccessibilityInputConnection getCurrentInputConnection()

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

final EditorInfo getCurrentInputEditorInfo()

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

final boolean getCurrentInputStarted()

Whether the input has started.

void onFinishInput()

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

void onStartInput(EditorInfo attribute, boolean restarting)

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

void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd, int candidatesStart, int candidatesEnd)

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

Inherited methods

Public constructors

InputMethod

Added in API level 33
public InputMethod (AccessibilityService service)

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
public final InputMethod.AccessibilityInputConnection getCurrentInputConnection ()

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

Returns
InputMethod.AccessibilityInputConnection

getCurrentInputEditorInfo

Added in API level 33
public final EditorInfo getCurrentInputEditorInfo ()

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

Returns
EditorInfo This value may be null.

getCurrentInputStarted

Added in API level 33
public final boolean getCurrentInputStarted ()

Whether the input has started.

Returns
boolean

onFinishInput

Added in API level 33
public void onFinishInput ()

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
public void onStartInput (EditorInfo attribute, 
                boolean restarting)

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
public void onUpdateSelection (int oldSelStart, 
                int oldSelEnd, 
                int newSelStart, 
                int newSelEnd, 
                int candidatesStart, 
                int candidatesEnd)

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.

Parameters
oldSelStart int

oldSelEnd int

newSelStart int

newSelEnd int

candidatesStart int

candidatesEnd int