# InputMethodSession

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Nested Classes](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession#nestedclasses)\|[Methods](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession#pubmethods)  

# InputMethodSession

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/view/inputmethod/InputMethodSession "View this page in Kotlin")\|Java

`
public


interface
InputMethodSession
`  
`


`

|---------------------------------------------|
| android.view.inputmethod.InputMethodSession |

|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known indirect subclasses [AbstractInputMethodService.AbstractInputMethodSessionImpl](https://developer.android.com/reference/android/inputmethodservice/AbstractInputMethodService.AbstractInputMethodSessionImpl),[InputMethodService.InputMethodSessionImpl](https://developer.android.com/reference/android/inputmethodservice/InputMethodService.InputMethodSessionImpl) |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [AbstractInputMethodService.AbstractInputMethodSessionImpl](https://developer.android.com/reference/android/inputmethodservice/AbstractInputMethodService.AbstractInputMethodSessionImpl) | Base class for derived classes to implement their[InputMethodSession](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession)interface.                                                                                                                       | | [InputMethodService.InputMethodSessionImpl](https://developer.android.com/reference/android/inputmethodservice/InputMethodService.InputMethodSessionImpl)                                 | Concrete implementation of[AbstractInputMethodService.AbstractInputMethodSessionImpl](https://developer.android.com/reference/android/inputmethodservice/AbstractInputMethodService.AbstractInputMethodSessionImpl)that provides all of the standard behavior for an input method session. | |

<br />

*** ** * ** ***

The InputMethodSession interface provides the per-client functionality of[InputMethod](https://developer.android.com/reference/android/view/inputmethod/InputMethod)that is safe to expose to applications.

Applications will not normally use this interface themselves, instead relying on the standard interaction provided by[TextView](https://developer.android.com/reference/android/widget/TextView)and[EditText](https://developer.android.com/reference/android/widget/EditText).

## Summary

|                                                                     ### Nested classes                                                                     ||
|--------------|----------------------------------------------------------------------------------------------------------------------------------------------|
| ` interface` | [InputMethodSession.EventCallback](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession.EventCallback) <br /> |

|                                                                                                                                                                                                                                                                                                                                                                                                         ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                         ||
|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract void` | ` `[appPrivateCommand](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession#appPrivateCommand(java.lang.String,%20android.os.Bundle))`(`[String](https://developer.android.com/reference/java/lang/String)` action, `[Bundle](https://developer.android.com/reference/android/os/Bundle)` data) ` Process a private command sent from the application to the input method.                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` abstract void` | ` `[dispatchGenericMotionEvent](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession#dispatchGenericMotionEvent(int,%20android.view.MotionEvent,%20android.view.inputmethod.InputMethodSession.EventCallback))`(int seq, `[MotionEvent](https://developer.android.com/reference/android/view/MotionEvent)` event, `[InputMethodSession.EventCallback](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession.EventCallback)` callback) ` This method is called when there is a generic motion event.                                                                                                                                                                                                                                                 |
| ` abstract void` | ` `[dispatchKeyEvent](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession#dispatchKeyEvent(int,%20android.view.KeyEvent,%20android.view.inputmethod.InputMethodSession.EventCallback))`(int seq, `[KeyEvent](https://developer.android.com/reference/android/view/KeyEvent)` event, `[InputMethodSession.EventCallback](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession.EventCallback)` callback) ` This method is called when a key is pressed.                                                                                                                                                                                                                                                                                             |
| ` abstract void` | ` `[dispatchTrackballEvent](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession#dispatchTrackballEvent(int,%20android.view.MotionEvent,%20android.view.inputmethod.InputMethodSession.EventCallback))`(int seq, `[MotionEvent](https://developer.android.com/reference/android/view/MotionEvent)` event, `[InputMethodSession.EventCallback](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession.EventCallback)` callback) ` This method is called when there is a track ball event.                                                                                                                                                                                                                                                             |
| ` abstract void` | ` `[displayCompletions](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession#displayCompletions(android.view.inputmethod.CompletionInfo[]))`(`[CompletionInfo[]](https://developer.android.com/reference/android/view/inputmethod/CompletionInfo)` completions) ` Called by a text editor that performs auto completion, to tell the input method about the completions it has available.                                                                                                                                                                                                                                                                                                                                                                                         |
| ` abstract void` | ` `[finishInput](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession#finishInput())`() ` This method is called when the application would like to stop receiving text input.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` abstract void` | ` `[toggleSoftInput](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession#toggleSoftInput(int,%20int))`(int showFlags, int hideFlags) ` *This method was deprecated in API level 31. Starting in[Build.VERSION_CODES.S](https://developer.android.com/reference/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[InputMethodService.requestShowSelf(int)](https://developer.android.com/reference/android/inputmethodservice/InputMethodService#requestShowSelf(int))or[InputMethodService.requestHideSelf](https://developer.android.com/reference/android/inputmethodservice/InputMethodService#requestHideSelf(int))* |
| ` abstract void` | ` `[updateCursor](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession#updateCursor(android.graphics.Rect))`(`[Rect](https://developer.android.com/reference/android/graphics/Rect)` newCursor) ` This method is called when cursor location of the target input field has changed within its window.                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` abstract void` | ` `[updateCursorAnchorInfo](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession#updateCursorAnchorInfo(android.view.inputmethod.CursorAnchorInfo))`(`[CursorAnchorInfo](https://developer.android.com/reference/android/view/inputmethod/CursorAnchorInfo)` cursorAnchorInfo) ` This method is called when the cursor and/or the character position relevant to text input is changed on the screen.                                                                                                                                                                                                                                                                                                                                                                             |
| ` abstract void` | ` `[updateExtractedText](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession#updateExtractedText(int,%20android.view.inputmethod.ExtractedText))`(int token, `[ExtractedText](https://developer.android.com/reference/android/view/inputmethod/ExtractedText)` text) ` Called by a text editor to report its new extracted text when its contents change.                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` abstract void` | ` `[updateSelection](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession#updateSelection(int,%20int,%20int,%20int,%20int,%20int))`(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd, int candidatesStart, int candidatesEnd) ` This method is called when the selection or cursor in the current target input field has changed.                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` abstract void` | ` `[viewClicked](https://developer.android.com/reference/android/view/inputmethod/InputMethodSession#viewClicked(boolean))`(boolean focusChanged) ` This method is called when the user tapped a text view.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |

## Public methods

### appPrivateCommand

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void appPrivateCommand (String action, 
                Bundle data)
```

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.

<br />

|                                                                                                 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. <br /> |
| `data`   | `Bundle`: Any data to include with the command. <br />                                                                                                                                           |

### dispatchGenericMotionEvent

Added in[API level 17](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void dispatchGenericMotionEvent (int seq, 
                MotionEvent event, 
                InputMethodSession.EventCallback callback)
```

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.

<br />

|                      Parameters                       ||
|------------|-------------------------------------------|
| `seq`      | `int` <br />                              |
| `event`    | `MotionEvent`: The motion event. <br />   |
| `callback` | `InputMethodSession.EventCallback` <br /> |

|                               Returns                               ||
|--------|-------------------------------------------------------------|
| `void` | Whether the input method wants to handle this event. <br /> |

**See also:**

- [MotionEvent](https://developer.android.com/reference/android/view/MotionEvent)  

### dispatchKeyEvent

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void dispatchKeyEvent (int seq, 
                KeyEvent event, 
                InputMethodSession.EventCallback callback)
```

This method is called when a key is pressed. When done with the event, the implementation must call back on<var translate="no">callback</var>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.

<br />

|                      Parameters                       ||
|------------|-------------------------------------------|
| `seq`      | `int` <br />                              |
| `event`    | `KeyEvent`: The key event. <br />         |
| `callback` | `InputMethodSession.EventCallback` <br /> |

|                               Returns                               ||
|--------|-------------------------------------------------------------|
| `void` | Whether the input method wants to handle this event. <br /> |

**See also:**

- [KeyEvent](https://developer.android.com/reference/android/view/KeyEvent)  

### dispatchTrackballEvent

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void dispatchTrackballEvent (int seq, 
                MotionEvent event, 
                InputMethodSession.EventCallback callback)
```

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.

<br />

|                      Parameters                       ||
|------------|-------------------------------------------|
| `seq`      | `int` <br />                              |
| `event`    | `MotionEvent`: The motion event. <br />   |
| `callback` | `InputMethodSession.EventCallback` <br /> |

|                               Returns                               ||
|--------|-------------------------------------------------------------|
| `void` | Whether the input method wants to handle this event. <br /> |

**See also:**

- [MotionEvent](https://developer.android.com/reference/android/view/MotionEvent)  

### displayCompletions

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void displayCompletions (CompletionInfo[] completions)
```

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.

<br />

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

### finishInput

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void finishInput ()
```

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

<br />

### toggleSoftInput

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void toggleSoftInput (int showFlags, 
                int hideFlags)
```

<br />

**This method was deprecated in API level 31.**   
Starting in[Build.VERSION_CODES.S](https://developer.android.com/reference/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[InputMethodService.requestShowSelf(int)](https://developer.android.com/reference/android/inputmethodservice/InputMethodService#requestShowSelf(int))or[InputMethodService.requestHideSelf](https://developer.android.com/reference/android/inputmethodservice/InputMethodService#requestHideSelf(int))

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

<br />

|                                                                                                                                                                          Parameters                                                                                                                                                                           ||
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `showFlags` | `int`: Value is either`0`or a combination of[InputMethodManager.SHOW_IMPLICIT](https://developer.android.com/reference/android/view/inputmethod/InputMethodManager#SHOW_IMPLICIT), and[InputMethodManager.SHOW_FORCED](https://developer.android.com/reference/android/view/inputmethod/InputMethodManager#SHOW_FORCED) <br />                   |
| `hideFlags` | `int`: Value is either`0`or a combination of[InputMethodManager.HIDE_IMPLICIT_ONLY](https://developer.android.com/reference/android/view/inputmethod/InputMethodManager#HIDE_IMPLICIT_ONLY), and[InputMethodManager.HIDE_NOT_ALWAYS](https://developer.android.com/reference/android/view/inputmethod/InputMethodManager#HIDE_NOT_ALWAYS) <br /> |

### updateCursor

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void updateCursor (Rect newCursor)
```

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.

<br />

|                                                       Parameters                                                       ||
|-------------|-----------------------------------------------------------------------------------------------------------|
| `newCursor` | `Rect`: The rectangle of the cursor currently being shown in the input field's window coordinates. <br /> |

### updateCursorAnchorInfo

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void updateCursorAnchorInfo (CursorAnchorInfo cursorAnchorInfo)
```

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.

<br />

|                                                                     Parameters                                                                     ||
|--------------------|--------------------------------------------------------------------------------------------------------------------------------|
| `cursorAnchorInfo` | `CursorAnchorInfo`: Positional information relevant to text input, such as text insertion point and composition string. <br /> |

### updateExtractedText

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void updateExtractedText (int token, 
                ExtractedText text)
```

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()](https://developer.android.com/reference/android/view/inputmethod/InputConnection#getExtractedText(android.view.inputmethod.ExtractedTextRequest,%20int))with the option to report updates.

<br />

|                                     Parameters                                      ||
|---------|----------------------------------------------------------------------------|
| `token` | `int`: The input method supplied token for identifying its request. <br /> |
| `text`  | `ExtractedText`: The new extracted text. <br />                            |

### updateSelection

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void updateSelection (int oldSelStart, 
                int oldSelEnd, 
                int newSelStart, 
                int newSelEnd, 
                int candidatesStart, 
                int candidatesEnd)
```

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

<br />

|                                            Parameters                                             ||
|-------------------|--------------------------------------------------------------------------------|
| `oldSelStart`     | `int`: The previous text offset of the cursor selection start position. <br /> |
| `oldSelEnd`       | `int`: The previous text offset of the cursor selection end position. <br />   |
| `newSelStart`     | `int`: The new text offset of the cursor selection start position. <br />      |
| `newSelEnd`       | `int`: The new text offset of the cursor selection end position. <br />        |
| `candidatesStart` | `int`: The text offset of the current candidate text start position. <br />    |
| `candidatesEnd`   | `int`: The text offset of the current candidate text end position. <br />      |

### viewClicked

Added in[API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void viewClicked (boolean focusChanged)
```

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.

<br />

|                                         Parameters                                         ||
|----------------|----------------------------------------------------------------------------|
| `focusChanged` | `boolean`: true if the user changed the focused view by this click. <br /> |