to top
Android APIs
public interface

InputMethod

android.view.inputmethod.InputMethod
Known Indirect Subclasses

Class Overview

The InputMethod interface represents an input method which can generate key events and text, such as digital, email addresses, CJK characters, other language characters, and etc., while handling various input events, and send the text back to the application that requests text input. See InputMethodManager for more general information about the architecture.

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

Those implementing input methods should normally do so by deriving from InputMethodService or one of its subclasses. When implementing an input method, the service component containing it must also supply a SERVICE_META_DATA meta-data field, referencing an XML resource providing details about the input method. All input methods also must require that clients hold the BIND_INPUT_METHOD in order to interact with the service; if this is not required, the system will not use that input method, because it can not trust that it is not compromised.

The InputMethod interface is actually split into two parts: the interface here is the top-level interface to the input method, providing all access to it, which only the system can access (due to the BIND_INPUT_METHOD permission requirement). In addition its method createSession(android.view.inputmethod.InputMethod.SessionCallback) can be called to instantate a secondary InputMethodSession interface which is what clients use to communicate with the input method.

Summary

Nested Classes
interface InputMethod.SessionCallback  
Constants
String SERVICE_INTERFACE This is the interface name that a service implementing an input method should say that it supports -- that is, this is the action it uses for its intent filter.
String SERVICE_META_DATA Name under which an InputMethod service component publishes information about itself.
int SHOW_EXPLICIT Flag for showSoftInput(int, ResultReceiver): this show has been explicitly requested by the user.
int SHOW_FORCED Flag for showSoftInput(int, ResultReceiver): this show has been forced to happen by the user.
Public Methods
abstract void attachToken(IBinder token)
Called first thing after an input method is created, this supplies a unique token for the session it has with the system service.
abstract void bindInput(InputBinding binding)
Bind a new application environment in to the input method, so that it can later start and stop input processing.
abstract void changeInputMethodSubtype(InputMethodSubtype subtype)
Notify that the input method subtype is being changed in the same input method.
abstract void createSession(InputMethod.SessionCallback callback)
Create a new InputMethodSession that can be handed to client applications for interacting with the input method.
abstract void hideSoftInput(int flags, ResultReceiver resultReceiver)
Request that any soft input part of the input method be hidden from the user.
abstract void restartInput(InputConnection inputConnection, EditorInfo attribute)
This method is called when the state of this input method needs to be reset.
abstract void revokeSession(InputMethodSession session)
Disable and destroy a session that was previously created with createSession(android.view.inputmethod.InputMethod.SessionCallback).
abstract void setSessionEnabled(InputMethodSession session, boolean enabled)
Control whether a particular input method session is active.
abstract void showSoftInput(int flags, ResultReceiver resultReceiver)
Request that any soft input part of the input method be shown to the user.
abstract void startInput(InputConnection inputConnection, EditorInfo info)
This method is called when the application starts to receive text and it is ready for this input method to process received events and send result text back to the application.
abstract void unbindInput()
Unbind an application environment, called when the information previously set by bindInput(InputBinding) is no longer valid for this input method.

Constants

public static final String SERVICE_INTERFACE

Added in API level 3

This is the interface name that a service implementing an input method should say that it supports -- that is, this is the action it uses for its intent filter. To be supported, the service must also require the BIND_INPUT_METHOD permission so that other applications can not abuse it.

Constant Value: "android.view.InputMethod"

public static final String SERVICE_META_DATA

Added in API level 3

Name under which an InputMethod service component publishes information about itself. This meta-data must reference an XML resource containing an <input-method> tag.

Constant Value: "android.view.im"

public static final int SHOW_EXPLICIT

Added in API level 3

Flag for showSoftInput(int, ResultReceiver): this show has been explicitly requested by the user. If not set, the system has decided it may be a good idea to show the input method based on a navigation operation in the UI.

Constant Value: 1 (0x00000001)

public static final int SHOW_FORCED

Added in API level 3

Flag for showSoftInput(int, ResultReceiver): this show has been forced to happen by the user. If set, the input method should remain visible until deliberated dismissed by the user in its UI.

Constant Value: 2 (0x00000002)

Public Methods

public abstract void attachToken (IBinder token)

Added in API level 3

Called first thing after an input method is created, this supplies a unique token for the session it has with the system service. It is needed to identify itself with the service to validate its operations. This token must not be passed to applications, since it grants special priviledges that should not be given to applications.

Note: to protect yourself from malicious clients, you should only accept the first token given to you. Any after that may come from the client.

public abstract void bindInput (InputBinding binding)

Added in API level 3

Bind a new application environment in to the input method, so that it can later start and stop input processing. Typically this method is called when this input method is enabled in an application for the first time.

Parameters
binding Information about the application window that is binding to the input method.

public abstract void changeInputMethodSubtype (InputMethodSubtype subtype)

Added in API level 11

Notify that the input method subtype is being changed in the same input method.

Parameters
subtype New subtype of the notified input method

public abstract void createSession (InputMethod.SessionCallback callback)

Added in API level 3

Create a new InputMethodSession that can be handed to client applications for interacting with the input method. You can later use revokeSession(InputMethodSession) to destroy the session so that it can no longer be used by any clients.

Parameters
callback Interface that is called with the newly created session.

public abstract void hideSoftInput (int flags, ResultReceiver resultReceiver)

Added in API level 3

Request that any soft input part of the input method be hidden from the user.

Parameters
flags Provides additional information about the show request. Currently always 0.
resultReceiver The client requesting the show may wish to be told the impact of their request, which should be supplied here. The result code should be InputMethodManager.RESULT_UNCHANGED_SHOWN, InputMethodManager.RESULT_UNCHANGED_HIDDEN, InputMethodManager.RESULT_SHOWN, or InputMethodManager.RESULT_HIDDEN.

public abstract void restartInput (InputConnection inputConnection, EditorInfo attribute)

Added in API level 3

This method is called when the state of this input method needs to be reset.

Typically, this method is called when the input focus is moved from one text box to another.

Parameters
inputConnection Optional specific input connection for communicating with the text box; if null, you should use the generic bound input connection.
attribute The attribute of the text box (typically, a EditText) that requests input.
See Also

public abstract void revokeSession (InputMethodSession session)

Added in API level 3

Disable and destroy a session that was previously created with createSession(android.view.inputmethod.InputMethod.SessionCallback). After this call, the given session interface is no longer active and calls on it will fail.

Parameters
session The InputMethodSession previously provided through SessionCallback.sessionCreated() that is to be revoked.

public abstract void setSessionEnabled (InputMethodSession session, boolean enabled)

Added in API level 3

Control whether a particular input method session is active.

Parameters
session The InputMethodSession previously provided through SessionCallback.sessionCreated() that is to be changed.

public abstract void showSoftInput (int flags, ResultReceiver resultReceiver)

Added in API level 3

Request that any soft input part of the input method be shown to the user.

Parameters
flags Provides additional information about the show request. Currently may be 0 or have the bit SHOW_EXPLICIT set.
resultReceiver The client requesting the show may wish to be told the impact of their request, which should be supplied here. The result code should be InputMethodManager.RESULT_UNCHANGED_SHOWN, InputMethodManager.RESULT_UNCHANGED_HIDDEN, InputMethodManager.RESULT_SHOWN, or InputMethodManager.RESULT_HIDDEN.

public abstract void startInput (InputConnection inputConnection, EditorInfo info)

Added in API level 3

This method is called when the application starts to receive text and it is ready for this input method to process received events and send result text back to the application.

Parameters
inputConnection Optional specific input connection for communicating with the text box; if null, you should use the generic bound input connection.
info Information about the text box (typically, an EditText) that requests input.
See Also

public abstract void unbindInput ()

Added in API level 3

Unbind an application environment, called when the information previously set by bindInput(InputBinding) is no longer valid for this input method.

Typically this method is called when the application changes to be non-foreground.