# AccessibilityService.SoftKeyboardController

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

# SoftKeyboardController

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.SoftKeyboardController "View this page in Java")  

```
class SoftKeyboardController
```

|---|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                                                                       ||
| ↳ | [android.accessibilityservice.AccessibilityService.SoftKeyboardController](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#) |

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[AccessibilityService.SHOW_MODE_AUTO](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService#SHOW_MODE_AUTO:kotlin.Int), 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.

## Summary

|                                                                                                                Nested classes                                                                                                                 ||
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| abstract | [OnShowModeChangedListener](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController.OnShowModeChangedListener) Listener for changes in the soft keyboard show mode. |

|                                                                                                                                                                                                                                                          Constants                                                                                                                                                                                                                                                           ||
|----------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ENABLE_IME_FAIL_BY_ADMIN](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#ENABLE_IME_FAIL_BY_ADMIN:kotlin.Int) Return value for[setInputMethodEnabled(java.lang.String,boolean)](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#setInputMethodEnabled(kotlin.String,%20kotlin.Boolean)). |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ENABLE_IME_FAIL_UNKNOWN](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#ENABLE_IME_FAIL_UNKNOWN:kotlin.Int) Return value for[setInputMethodEnabled(java.lang.String,boolean)](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#setInputMethodEnabled(kotlin.String,%20kotlin.Boolean)).   |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ENABLE_IME_SUCCESS](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#ENABLE_IME_SUCCESS:kotlin.Int) Return value for[setInputMethodEnabled(java.lang.String,boolean)](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#setInputMethodEnabled(kotlin.String,%20kotlin.Boolean)).             |

|                                                                                                                                                                                                                                                                                                                                                                                                                Public methods                                                                                                                                                                                                                                                                                                                                                                                                                ||
|------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)       | [addOnShowModeChangedListener](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#addOnShowModeChangedListener(android.accessibilityservice.AccessibilityService.SoftKeyboardController.OnShowModeChangedListener))`(`listener:` `[AccessibilityService.SoftKeyboardController.OnShowModeChangedListener](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController.OnShowModeChangedListener)`)` Adds the specified change listener to the list of show mode change listeners.                                                                                                                                       |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)       | [addOnShowModeChangedListener](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#addOnShowModeChangedListener(android.accessibilityservice.AccessibilityService.SoftKeyboardController.OnShowModeChangedListener,%20android.os.Handler))`(`listener:` `[AccessibilityService.SoftKeyboardController.OnShowModeChangedListener](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController.OnShowModeChangedListener)`, `handler:` `[Handler](https://developer.android.com/reference/kotlin/android/os/Handler.html#)?`)` Adds the specified change listener to the list of soft keyboard show mode change listeners. |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)         | [getShowMode](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#getShowMode())`()` Returns the show mode of the soft keyboard.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [removeOnShowModeChangedListener](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#removeOnShowModeChangedListener(android.accessibilityservice.AccessibilityService.SoftKeyboardController.OnShowModeChangedListener))`(`listener:` `[AccessibilityService.SoftKeyboardController.OnShowModeChangedListener](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController.OnShowModeChangedListener)`)` Removes the specified change listener from the list of keyboard show mode change listeners.                                                                                                                   |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)         | [setInputMethodEnabled](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#setInputMethodEnabled(kotlin.String,%20kotlin.Boolean))`(`imeId:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `enabled:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Enable or disable the specified IME for the user for whom the service is activated.                                                                                                                                                                                                                                                              |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [setShowMode](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#setShowMode(kotlin.Int))`(`showMode:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets the soft keyboard show mode.                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [switchToInputMethod](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#switchToInputMethod(kotlin.String))`(`imeId:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` Switches the current IME for the user for whom the service is enabled.                                                                                                                                                                                                                                                                                                                                                                                                  |

## Constants

### ENABLE_IME_FAIL_BY_ADMIN

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

```
static val ENABLE_IME_FAIL_BY_ADMIN: Int
```

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

    Value: 1

### ENABLE_IME_FAIL_UNKNOWN

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

```
static val ENABLE_IME_FAIL_UNKNOWN: Int
```

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

    Value: 2

### ENABLE_IME_SUCCESS

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

```
static val ENABLE_IME_SUCCESS: Int
```

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

    Value: 0

## Public methods

### addOnShowModeChangedListener

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

```
fun addOnShowModeChangedListener(listener: AccessibilityService.SoftKeyboardController.OnShowModeChangedListener): Unit
```

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.

|                                                                                                                             Parameters                                                                                                                             ||
|------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `listener` | [AccessibilityService.SoftKeyboardController.OnShowModeChangedListener](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController.OnShowModeChangedListener):This value cannot be`null`. |

### addOnShowModeChangedListener

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

```
fun addOnShowModeChangedListener(
    listener: AccessibilityService.SoftKeyboardController.OnShowModeChangedListener, 
    handler: Handler?
): Unit
```

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

|                                                                                                                                  Parameters                                                                                                                                  ||
|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `listener` | [AccessibilityService.SoftKeyboardController.OnShowModeChangedListener](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController.OnShowModeChangedListener):the listener to add, must be non-null |
| `handler`  | [Handler](https://developer.android.com/reference/kotlin/android/os/Handler.html#)?:the handler on which to callback should execute, or`null`to execute on the service's main thread                                                                             |

### getShowMode

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

```
fun getShowMode(): Int
```

Returns the show mode of the soft keyboard.

|                                                                                                                                                                                                                                                                                                                                                                           Return                                                                                                                                                                                                                                                                                                                                                                            ||
|----------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | the current soft keyboard show mode Value is[android.accessibilityservice.AccessibilityService#SHOW_MODE_AUTO](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService#SHOW_MODE_AUTO:kotlin.Int),[android.accessibilityservice.AccessibilityService#SHOW_MODE_HIDDEN](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService#SHOW_MODE_HIDDEN:kotlin.Int), or[android.accessibilityservice.AccessibilityService#SHOW_MODE_IGNORE_HARD_KEYBOARD](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService#SHOW_MODE_IGNORE_HARD_KEYBOARD:kotlin.Int) |

**See Also**

- [android.accessibilityservice.AccessibilityService#SHOW_MODE_AUTO](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService#SHOW_MODE_AUTO:kotlin.Int)
- [android.accessibilityservice.AccessibilityService#SHOW_MODE_HIDDEN](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService#SHOW_MODE_HIDDEN:kotlin.Int)
- [android.accessibilityservice.AccessibilityService#SHOW_MODE_IGNORE_HARD_KEYBOARD](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService#SHOW_MODE_IGNORE_HARD_KEYBOARD:kotlin.Int)  

### removeOnShowModeChangedListener

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

```
fun removeOnShowModeChangedListener(listener: AccessibilityService.SoftKeyboardController.OnShowModeChangedListener): Boolean
```

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

|                                                                                                                                   Parameters                                                                                                                                    ||
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `listener` | [AccessibilityService.SoftKeyboardController.OnShowModeChangedListener](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController.OnShowModeChangedListener):the listener to remove, must be non-null |

|                                                                 Return                                                                 ||
|------------------------------------------------------------------------------------|----------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `true`if the listener was removed,`false`otherwise |

### setInputMethodEnabled

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

```
fun setInputMethodEnabled(
    imeId: String, 
    enabled: Boolean
): Int
```

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.

|                                                                                              Parameters                                                                                              ||
|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `imeId`   | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):The ID of the input method to enable or disable. This IME must be installed. This value cannot be`null`. |
| `enabled` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html):`true`if the input method associated with`imeId`should be enabled.                                     |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Return                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ||
|----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | status code for the result of enabling/disabling the input method associated with`imeId`. Value is[android.accessibilityservice.AccessibilityService.SoftKeyboardController#ENABLE_IME_SUCCESS](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#ENABLE_IME_SUCCESS:kotlin.Int),[android.accessibilityservice.AccessibilityService.SoftKeyboardController#ENABLE_IME_FAIL_BY_ADMIN](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#ENABLE_IME_FAIL_BY_ADMIN:kotlin.Int), or[android.accessibilityservice.AccessibilityService.SoftKeyboardController#ENABLE_IME_FAIL_UNKNOWN](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService.SoftKeyboardController#ENABLE_IME_FAIL_UNKNOWN:kotlin.Int) |

|                                          Exceptions                                           ||
|-------------------------------|----------------------------------------------------------------|
| `java.lang.SecurityException` | if the input method is not in the same package as the service. |

**See Also**

- [android.view.inputmethod.InputMethodInfo#getId()](https://developer.android.com/reference/kotlin/android/view/inputmethod/InputMethodInfo.html#getId())  

### setShowMode

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

```
fun setShowMode(showMode: Int): Boolean
```

Sets the soft keyboard show mode.

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

|                                                                                                                                                                                                                                                                                                                                                                                 Parameters                                                                                                                                                                                                                                                                                                                                                                                 ||
|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `showMode` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the new show mode for the soft keyboard Value is[android.accessibilityservice.AccessibilityService#SHOW_MODE_AUTO](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService#SHOW_MODE_AUTO:kotlin.Int),[android.accessibilityservice.AccessibilityService#SHOW_MODE_HIDDEN](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService#SHOW_MODE_HIDDEN:kotlin.Int), or[android.accessibilityservice.AccessibilityService#SHOW_MODE_IGNORE_HARD_KEYBOARD](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService#SHOW_MODE_IGNORE_HARD_KEYBOARD:kotlin.Int) |

|                                                Return                                                ||
|------------------------------------------------------------------------------------|------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `true`on success |

**See Also**

- [android.accessibilityservice.AccessibilityService#SHOW_MODE_AUTO](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService#SHOW_MODE_AUTO:kotlin.Int)
- [android.accessibilityservice.AccessibilityService#SHOW_MODE_HIDDEN](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService#SHOW_MODE_HIDDEN:kotlin.Int)
- [android.accessibilityservice.AccessibilityService#SHOW_MODE_IGNORE_HARD_KEYBOARD](https://developer.android.com/reference/kotlin/android/accessibilityservice/AccessibilityService#SHOW_MODE_IGNORE_HARD_KEYBOARD:kotlin.Int)  

### switchToInputMethod

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

```
fun switchToInputMethod(imeId: String): Boolean
```

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.

|                                                                                                Parameters                                                                                                 ||
|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `imeId` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):The ID of the input method to make current. This IME must be installed and enabled. This value cannot be`null`. |

|                                                                                                                                                 Return                                                                                                                                                 ||
|------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `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 |

**See Also**

- [android.view.inputmethod.InputMethodInfo#getId()](https://developer.android.com/reference/kotlin/android/view/inputmethod/InputMethodInfo.html#getId())