Added in API level 3

AbstractInputMethodService

abstract class AbstractInputMethodService : Service, KeyEvent.Callback
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Service
   ↳ android.inputmethodservice.AbstractInputMethodService

AbstractInputMethodService provides a abstract base class for input methods. Normal input method implementations will not derive from this directly, instead building on top of InputMethodService or another more complete base class. Be sure to read InputMethod for more information on the basics of writing input methods.

This class combines a Service (representing the input method component to the system with the InputMethod interface that input methods must implement. This base class takes care of reporting your InputMethod from the service when clients bind to it, but provides no standard implementation of the InputMethod interface itself. Derived classes must implement that interface.

After android.os.Build.VERSION_CODES#S, the maximum possible area to show the soft input may not be the entire screen. For example, some devices may support to show the soft input on only half of screen.

In that case, moving the soft input from one half screen to another will trigger a android.content.res.Resources update to match the new Configuration and this AbstractInputMethodService may also receive a #onConfigurationChanged(android.content.res.Configuration) callback if there's notable configuration changes

Summary

Nested classes
abstract

Base class for derived classes to implement their InputMethod interface.

abstract

Base class for derived classes to implement their InputMethodSession interface.

Inherited constants
Public constructors

Public methods
open KeyEvent.DispatcherState!

Return the global KeyEvent.DispatcherState for used for processing events from the target application.

open Any!

Return the handle to a system-level service by name.

IBinder?
onBind(intent: Intent!)

open Unit

Called by the system when the device configuration changes while your component is running.

abstract AbstractInputMethodService.AbstractInputMethodImpl!

Called by the framework during initialization, when the InputMethod interface for this service needs to be created.

abstract AbstractInputMethodService.AbstractInputMethodSessionImpl!

Called by the framework when a new InputMethodSession interface is needed for a new client of the input method.

open Unit

Called by the system to notify a Service that it is no longer used and is being removed.

open Boolean

Implement this to handle generic motion events on your input method.

open Unit

Override Service's empty implementation and listen to ActivityThread for low memory and trim memory events.

open Boolean

Implement this to handle trackball events on your input method.

open Unit
onTrimMemory(level: Int)

open Unit

Add a new ComponentCallbacks to the base application of the Context, which will be called at the same times as the ComponentCallbacks methods of activities and other components are called.

open Unit

Remove a ComponentCallbacks object that was previously registered with registerComponentCallbacks(android.content.ComponentCallbacks).

Protected methods
open Unit
dump(fd: FileDescriptor!, fout: PrintWriter!, args: Array<String!>!)

Implement this to handle android.

Inherited functions

Public constructors

AbstractInputMethodService

AbstractInputMethodService()

Public methods

getKeyDispatcherState

Added in API level 5
open fun getKeyDispatcherState(): KeyEvent.DispatcherState!

Return the global KeyEvent.DispatcherState for used for processing events from the target application. Normally you will not need to use this directly, but just use the standard high-level event callbacks like onKeyDown.

getSystemService

Added in API level 3
open fun getSystemService(name: String): Any!

Return the handle to a system-level service by name. The class of the returned object varies by the requested name. Currently available names are:

WINDOW_SERVICE ("window")
The top-level window manager in which you can place custom windows. The returned object is a android.view.WindowManager. Must only be obtained from a visual context such as Activity or a Context created with createWindowContext(int,android.os.Bundle), which are adjusted to the configuration and visual bounds of an area on screen.
LAYOUT_INFLATER_SERVICE ("layout_inflater")
A android.view.LayoutInflater for inflating layout resources in this context. Must only be obtained from a visual context such as Activity or a Context created with createWindowContext(int,android.os.Bundle), which are adjusted to the configuration and visual bounds of an area on screen.
ACTIVITY_SERVICE ("activity")
A android.app.ActivityManager for interacting with the global activity state of the system.
WALLPAPER_SERVICE ("wallpaper")
A android.service.wallpaper.WallpaperService for accessing wallpapers in this context. Must only be obtained from a visual context such as Activity or a Context created with createWindowContext(int,android.os.Bundle), which are adjusted to the configuration and visual bounds of an area on screen.
POWER_SERVICE ("power")
A android.os.PowerManager for controlling power management.
ALARM_SERVICE ("alarm")
A android.app.AlarmManager for receiving intents at the time of your choosing.
NOTIFICATION_SERVICE ("notification")
A android.app.NotificationManager for informing the user of background events.
KEYGUARD_SERVICE ("keyguard")
A android.app.KeyguardManager for controlling keyguard.
LOCATION_SERVICE ("location")
A android.location.LocationManager for controlling location (e.g., GPS) updates.
SEARCH_SERVICE ("search")
A android.app.SearchManager for handling search.
VIBRATOR_MANAGER_SERVICE ("vibrator_manager")
A android.os.VibratorManager for accessing the device vibrators, interacting with individual ones and playing synchronized effects on multiple vibrators.
VIBRATOR_SERVICE ("vibrator")
A android.os.Vibrator for interacting with the vibrator hardware.
CONNECTIVITY_SERVICE ("connectivity")
A ConnectivityManager for handling management of network connections.
IPSEC_SERVICE ("ipsec")
A IpSecManager for managing IPSec on sockets and networks.
WIFI_SERVICE ("wifi")
A WifiManager for management of Wi-Fi connectivity. On releases before Android 7, it should only be obtained from an application context, and not from any other derived context to avoid memory leaks within the calling process.
WIFI_AWARE_SERVICE ("wifiaware")
A WifiAwareManager for management of Wi-Fi Aware discovery and connectivity.
WIFI_P2P_SERVICE ("wifip2p")
A WifiP2pManager for management of Wi-Fi Direct connectivity.
INPUT_METHOD_SERVICE ("input_method")
An InputMethodManager for management of input methods.
UI_MODE_SERVICE ("uimode")
An android.app.UiModeManager for controlling UI modes.
DOWNLOAD_SERVICE ("download")
A android.app.DownloadManager for requesting HTTP downloads
BATTERY_SERVICE ("batterymanager")
A android.os.BatteryManager for managing battery state
JOB_SCHEDULER_SERVICE ("taskmanager")
A android.app.job.JobScheduler for managing scheduled tasks
NETWORK_STATS_SERVICE ("netstats")
A NetworkStatsManager for querying network usage statistics.
HARDWARE_PROPERTIES_SERVICE ("hardware_properties")
A android.os.HardwarePropertiesManager for accessing hardware properties.
DOMAIN_VERIFICATION_SERVICE ("domain_verification")
A android.content.pm.verify.domain.DomainVerificationManager for accessing web domain approval state.
DISPLAY_HASH_SERVICE ("display_hash")
A android.view.displayhash.DisplayHashManager for management of display hashes.

Note: System services obtained via this API may be closely associated with the Context in which they are obtained from. In general, do not share the service objects between various different contexts (Activities, Applications, Services, Providers, etc.)

Note: Instant apps, for which PackageManager#isInstantApp() returns true, don't have access to the following system services: DEVICE_POLICY_SERVICE, FINGERPRINT_SERVICE, KEYGUARD_SERVICE, SHORTCUT_SERVICE, USB_SERVICE, WALLPAPER_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WIFI_AWARE_SERVICE. For these services this method will return null. Generally, if you are running as an instant app you should always check whether the result of this method is null.

Note: When implementing this method, keep in mind that new services can be added on newer Android releases, so if you're looking for just the explicit names mentioned above, make sure to return null when you don't recognize the name — if you throw a RuntimeException exception instead, your app might break on new Android releases.

Parameters
name String: This value cannot be null.
Return
Any! The service or null if the name does not exist.

onBind

Added in API level 3
fun onBind(intent: Intent!): IBinder?
Parameters
intent Intent!: The Intent that was used to bind to this service, as given to android.content.Context#bindService. Note that any extras that were included with the Intent at that point will not be seen here.
Return
IBinder? Return an IBinder through which clients can call on to the service.

onConfigurationChanged

Added in API level 3
open fun onConfigurationChanged(configuration: Configuration): Unit

Called by the system when the device configuration changes while your component is running. Note that, unlike activities, other components are never restarted when a configuration changes: they must always deal with the results of the change, such as by re-retrieving resources.

At the time that this function has been called, your Resources object will have been updated to return resource values matching the new configuration.

For more information, read Handling Runtime Changes.

Parameters
newConfig The new device configuration. This value cannot be null.
configuration Configuration: This value cannot be null.

onCreateInputMethodInterface

Added in API level 3
abstract fun onCreateInputMethodInterface(): AbstractInputMethodService.AbstractInputMethodImpl!

Called by the framework during initialization, when the InputMethod interface for this service needs to be created.

onCreateInputMethodSessionInterface

Added in API level 3
abstract fun onCreateInputMethodSessionInterface(): AbstractInputMethodService.AbstractInputMethodSessionImpl!

Called by the framework when a new InputMethodSession interface is needed for a new client of the input method.

onDestroy

Added in API level 3
open fun onDestroy(): Unit

Called by the system to notify a Service that it is no longer used and is being removed. The service should clean up any resources it holds (threads, registered receivers, etc) at this point. Upon return, there will be no more calls in to this Service object and it is effectively dead. Do not call this method directly. If you override this method you must call through to the superclass implementation.

onGenericMotionEvent

Added in API level 17
open fun onGenericMotionEvent(event: MotionEvent!): Boolean

Implement this to handle generic motion events on your input method.

Parameters
event MotionEvent!: The motion event being received.
Return
Boolean True if the event was handled in this function, false otherwise.

onLowMemory

Added in API level 3
open fun onLowMemory(): Unit

Override Service's empty implementation and listen to ActivityThread for low memory and trim memory events.

onTrackballEvent

Added in API level 3
open fun onTrackballEvent(event: MotionEvent!): Boolean

Implement this to handle trackball events on your input method.

Parameters
event MotionEvent!: The motion event being received.
Return
Boolean True if the event was handled in this function, false otherwise.

registerComponentCallbacks

Added in API level 14
open fun registerComponentCallbacks(callback: ComponentCallbacks): Unit

Add a new ComponentCallbacks to the base application of the Context, which will be called at the same times as the ComponentCallbacks methods of activities and other components are called. Note that you must be sure to use unregisterComponentCallbacks when appropriate in the future; this will not be removed for you.

After Build.VERSION_CODES#TIRAMISU, the ComponentCallbacks will be registered to the base Context, and can be only used after attachBaseContext(android.content.Context). Users can still call to getApplicationContext().registerComponentCallbacks(ComponentCallbacks) to add ComponentCallbacks to the base application.

Parameters
callback ComponentCallbacks: This value cannot be null.
Exceptions
java.lang.IllegalStateException if this method calls before attachBaseContext(android.content.Context)

unregisterComponentCallbacks

Added in API level 14
open fun unregisterComponentCallbacks(callback: ComponentCallbacks): Unit

Remove a ComponentCallbacks object that was previously registered with registerComponentCallbacks(android.content.ComponentCallbacks).

After Build.VERSION_CODES#TIRAMISU, the ComponentCallbacks will be unregistered to the base Context, and can be only used after attachBaseContext(android.content.Context)

Parameters
callback ComponentCallbacks: This value cannot be null.
Exceptions
java.lang.IllegalStateException if this method calls before attachBaseContext(android.content.Context)

Protected methods

dump

Added in API level 3
protected open fun dump(
    fd: FileDescriptor!,
    fout: PrintWriter!,
    args: Array<String!>!
): Unit

Implement this to handle android.os.Binder#dump calls on your input method.

Parameters
fd FileDescriptor!: The raw file descriptor that the dump is being sent to.
writer The PrintWriter to which you should dump your state. This will be closed for you after you return.
args Array<String!>!: additional arguments to the dump request.