Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#nestedclasses) \| [Constants](https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#constants) \| [Methods](https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#inhmethods)

# AccessibilityService.SoftKeyboardController

*** ** * ** ***

` public static final class AccessibilityService.SoftKeyboardController `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.accessibilityservice.AccessibilityService.SoftKeyboardController |

<br />

*** ** * ** ***

Used to control, query, and listen for changes to the soft keyboard show mode.

Accessibility services may request to override the decisions normally made about whether or not the soft keyboard is shown.

If multiple services make conflicting requests, the last request is honored. A service may register a listener to find out if the mode has changed under it.

If the user takes action to override the behavior behavior requested by an accessibility service, the user's request takes precendence, the show mode will be reset to `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_AUTO`, and services will no longer be able to control that aspect of the soft keyboard's behavior.

Note: Because soft keyboards are independent apps, the framework does not have total control over their behavior. They may choose to show themselves, or not, without regard to requests made here. So the framework will make a best effort to deliver the behavior requested, but cannot guarantee success.
**See also:**

- `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_AUTO`
- `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_HIDDEN`
- `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_IGNORE_HARD_KEYBOARD`

## Summary

| ### Nested classes ||
|---|---|
| ` interface` | `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController.OnShowModeChangedListener` Listener for changes in the soft keyboard show mode. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#ENABLE_IME_FAIL_BY_ADMIN` Return value for `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#setInputMethodEnabled(java.lang.String,%20boolean)`. |
| `int` | `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#ENABLE_IME_FAIL_UNKNOWN` Return value for `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#setInputMethodEnabled(java.lang.String,%20boolean)`. |
| `int` | `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#ENABLE_IME_SUCCESS` Return value for `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#setInputMethodEnabled(java.lang.String,%20boolean)`. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#addOnShowModeChangedListener(android.accessibilityservice.AccessibilityService.SoftKeyboardController.OnShowModeChangedListener,%20android.os.Handler)(https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController.OnShowModeChangedListener listener, https://developer.android.com/reference/android/os/Handler handler) ` Adds the specified change listener to the list of soft keyboard show mode change listeners. |
| ` void` | ` https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#addOnShowModeChangedListener(android.accessibilityservice.AccessibilityService.SoftKeyboardController.OnShowModeChangedListener)(https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController.OnShowModeChangedListener listener) ` Adds the specified change listener to the list of show mode change listeners. |
| ` int` | ` https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#getShowMode()() ` Returns the show mode of the soft keyboard. |
| ` boolean` | ` https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#removeOnShowModeChangedListener(android.accessibilityservice.AccessibilityService.SoftKeyboardController.OnShowModeChangedListener)(https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController.OnShowModeChangedListener listener) ` Removes the specified change listener from the list of keyboard show mode change listeners. |
| ` int` | ` https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#setInputMethodEnabled(java.lang.String,%20boolean)(https://developer.android.com/reference/java/lang/String imeId, boolean enabled) ` Enable or disable the specified IME for the user for whom the service is activated. |
| ` boolean` | ` https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#setShowMode(int)(int showMode) ` Sets the soft keyboard show mode. |
| ` boolean` | ` https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#switchToInputMethod(java.lang.String)(https://developer.android.com/reference/java/lang/String imeId) ` Switches the current IME for the user for whom the service is enabled. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Constants

### ENABLE_IME_FAIL_BY_ADMIN

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

```
public static final int ENABLE_IME_FAIL_BY_ADMIN
```

Return value for `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#setInputMethodEnabled(java.lang.String,%20boolean)`. The action failed because the InputMethod is not permitted by device policy manager.

<br />

Constant Value: 1 (0x00000001)

### ENABLE_IME_FAIL_UNKNOWN

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

```
public static final int ENABLE_IME_FAIL_UNKNOWN
```

Return value for `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#setInputMethodEnabled(java.lang.String,%20boolean)`. The action failed and the reason is unknown.

<br />

Constant Value: 2 (0x00000002)

### ENABLE_IME_SUCCESS

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

```
public static final int ENABLE_IME_SUCCESS
```

Return value for `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#setInputMethodEnabled(java.lang.String,%20boolean)`. The action succeeded.

<br />

Constant Value: 0 (0x00000000)

## Public methods

### addOnShowModeChangedListener

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

```
public void addOnShowModeChangedListener (AccessibilityService.SoftKeyboardController.OnShowModeChangedListener listener, 
                Handler handler)
```

Adds the specified change listener to the list of soft keyboard show mode change listeners. The callback will occur on the specified `https://developer.android.com/reference/android/os/Handler`'s thread, or on the services's main thread if the handler is `null`.

<br />

| Parameters ||
|---|---|
| `listener` | `AccessibilityService.SoftKeyboardController.OnShowModeChangedListener`: the listener to add, must be non-null <br /> |
| `handler` | `Handler`: the handler on which to callback should execute, or `null` to execute on the service's main thread <br /> |

### addOnShowModeChangedListener

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

```
public void addOnShowModeChangedListener (AccessibilityService.SoftKeyboardController.OnShowModeChangedListener listener)
```

Adds the specified change listener to the list of show mode change listeners. The callback will occur on the service's main thread. Listener is not called on registration.

<br />

| Parameters ||
|---|---|
| `listener` | `AccessibilityService.SoftKeyboardController.OnShowModeChangedListener`: This value cannot be `null`. <br /> |

### getShowMode

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

```
public int getShowMode ()
```

Returns the show mode of the soft keyboard.

<br />

| Returns ||
|---|---|
| `int` | the current soft keyboard show mode. Value is one of the following: - `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_AUTO` - `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_HIDDEN` - `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_IGNORE_HARD_KEYBOARD` |

**See also:**

- `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_AUTO`
- `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_HIDDEN`
- `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_IGNORE_HARD_KEYBOARD`

### removeOnShowModeChangedListener

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

```
public boolean removeOnShowModeChangedListener (AccessibilityService.SoftKeyboardController.OnShowModeChangedListener listener)
```

Removes the specified change listener from the list of keyboard show mode change listeners.

<br />

| Parameters ||
|---|---|
| `listener` | `AccessibilityService.SoftKeyboardController.OnShowModeChangedListener`: the listener to remove, must be non-null <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if the listener was removed, `false` otherwise <br /> |

### setInputMethodEnabled

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

```
public int setInputMethodEnabled (String imeId, 
                boolean enabled)
```

Enable or disable the specified IME for the user for whom the service is activated. The IME needs to be in the same package as the service and needs to be allowed by device policy, if there is one. The change will persist until the specified IME is next explicitly enabled or disabled by whatever means, such as user choice, and may persist beyond the life cycle of the requesting service.

<br />

| Parameters ||
|---|---|
| `imeId` | `String`: The ID of the input method to enable or disable. This IME must be installed. This value cannot be `null`. <br /> |
| `enabled` | `boolean`: `true` if the input method associated with `imeId` should be enabled. <br /> |

| Returns ||
|---|---|
| `int` | status code for the result of enabling/disabling the input method associated with `imeId`. Value is one of the following: - `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#ENABLE_IME_SUCCESS` - `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#ENABLE_IME_FAIL_BY_ADMIN` - `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController#ENABLE_IME_FAIL_UNKNOWN` |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException` | if the input method is not in the same package as the service. |

**See also:**

- `https://developer.android.com/reference/android/view/inputmethod/InputMethodInfo#getId()`

### setShowMode

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

```
public boolean setShowMode (int showMode)
```

Sets the soft keyboard show mode.

**Note:** If the service is not yet connected (e.g. `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#onServiceConnected()` has not yet been called) or the service has been disconnected, this method will have no effect and return `false`.

<br />

| Parameters ||
|---|---|
| `showMode` | `int`: the new show mode for the soft keyboard. Value is one of the following: - `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_AUTO` - `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_HIDDEN` - `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_IGNORE_HARD_KEYBOARD` |

| Returns ||
|---|---|
| `boolean` | `true` on success <br /> |

**See also:**

- `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_AUTO`
- `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_HIDDEN`
- `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#SHOW_MODE_IGNORE_HARD_KEYBOARD`

### switchToInputMethod

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

```
public boolean switchToInputMethod (String imeId)
```

Switches the current IME for the user for whom the service is enabled. The change will persist until the current IME is explicitly changed again, and may persist beyond the life cycle of the requesting service.

<br />

| Parameters ||
|---|---|
| `imeId` | `String`: The ID of the input method to make current. This IME must be installed and enabled. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if the current input method was successfully switched to the input method by `imeId`, `false` if the input method specified is not installed, not enabled, or otherwise not available to become the current IME <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/inputmethod/InputMethodInfo#getId()`