Added in API level 24

SoftKeyboardController


class SoftKeyboardController
kotlin.Any
   ↳ 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, 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

Listener for changes in the soft keyboard show mode.

Constants
static Int

Return value for setInputMethodEnabled(java.lang.String,boolean).

static Int

Return value for setInputMethodEnabled(java.lang.String,boolean).

static Int

Return value for setInputMethodEnabled(java.lang.String,boolean).

Public methods
Unit

Adds the specified change listener to the list of show mode change listeners.

Unit

Adds the specified change listener to the list of soft keyboard show mode change listeners.

Int

Returns the show mode of the soft keyboard.

Boolean

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

Int

Enable or disable the specified IME for the user for whom the service is activated.

Boolean
setShowMode(showMode: Int)

Sets the soft keyboard show mode.

Boolean

Switches the current IME for the user for whom the service is enabled.

Constants

ENABLE_IME_FAIL_BY_ADMIN

Added in API level 33
static val ENABLE_IME_FAIL_BY_ADMIN: Int

Return value for setInputMethodEnabled(java.lang.String,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
static val ENABLE_IME_FAIL_UNKNOWN: Int

Return value for setInputMethodEnabled(java.lang.String,boolean). The action failed and the reason is unknown.

Value: 2

ENABLE_IME_SUCCESS

Added in API level 33
static val ENABLE_IME_SUCCESS: Int

Return value for setInputMethodEnabled(java.lang.String,boolean). The action succeeded.

Value: 0

Public methods

addOnShowModeChangedListener

Added in API level 24
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: This value cannot be null.

addOnShowModeChangedListener

Added in API level 24
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's thread, or on the services's main thread if the handler is null.

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

removeOnShowModeChangedListener

Added in API level 24
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: the listener to remove, must be non-null
Return
Boolean true if the listener was removed, false otherwise

setInputMethodEnabled

Added in API level 33
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: The ID of the input method to enable or disable. This IME must be installed. This value cannot be null.
enabled Boolean: true if the input method associated with imeId should be enabled.
Return
Int status code for the result of enabling/disabling the input method associated with imeId. Value is android.accessibilityservice.AccessibilityService.SoftKeyboardController#ENABLE_IME_SUCCESS, android.accessibilityservice.AccessibilityService.SoftKeyboardController#ENABLE_IME_FAIL_BY_ADMIN, or android.accessibilityservice.AccessibilityService.SoftKeyboardController#ENABLE_IME_FAIL_UNKNOWN
Exceptions
java.lang.SecurityException if the input method is not in the same package as the service.

setShowMode

Added in API level 24
fun setShowMode(showMode: Int): Boolean

Sets the soft keyboard show mode.

Note: If the service is not yet connected (e.g. 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: the new show mode for the soft keyboard Value is android.accessibilityservice.AccessibilityService#SHOW_MODE_AUTO, android.accessibilityservice.AccessibilityService#SHOW_MODE_HIDDEN, or android.accessibilityservice.AccessibilityService#SHOW_MODE_IGNORE_HARD_KEYBOARD
Return
Boolean true on success

switchToInputMethod

Added in API level 30
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: The ID of the input method to make current. This IME must be installed and enabled. This value cannot be null.
Return
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