AbstractInputMethodService


public abstract class AbstractInputMethodService
extends Service implements KeyEvent.Callback

java.lang.Object
   ↳ 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 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 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

class AbstractInputMethodService.AbstractInputMethodImpl

Base class for derived classes to implement their InputMethod interface. 

class AbstractInputMethodService.AbstractInputMethodSessionImpl

Base class for derived classes to implement their InputMethodSession interface. 

Inherited constants

Public constructors

AbstractInputMethodService()

Public methods

KeyEvent.DispatcherState getKeyDispatcherState()

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

Object getSystemService(String name)

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

final IBinder onBind(Intent intent)

Return the communication channel to the service.

void onConfigurationChanged(Configuration configuration)

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

abstract AbstractInputMethodService.AbstractInputMethodImpl onCreateInputMethodInterface()

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

abstract AbstractInputMethodService.AbstractInputMethodSessionImpl onCreateInputMethodSessionInterface()

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

void onDestroy()

Called by the system to notify a Service that it is no longer used and is being removed. If you override this method you must call through to the superclass implementation.

boolean onGenericMotionEvent(MotionEvent event)

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

void onLowMemory()

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

boolean onTrackballEvent(MotionEvent event)

Implement this to handle trackball events on your input method.

void onTrimMemory(int level)

Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process.

void registerComponentCallbacks(ComponentCallbacks callback)

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.

void unregisterComponentCallbacks(ComponentCallbacks callback)

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

Protected methods

void dump(FileDescriptor fd, PrintWriter fout, String[] args)

Implement this to handle Binder.dump() calls on your input method.

Inherited methods

Public constructors

AbstractInputMethodService

public AbstractInputMethodService ()

Public methods

getKeyDispatcherState

Added in API level 5
public KeyEvent.DispatcherState getKeyDispatcherState ()

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 KeyEvent.Callback.onKeyDown(int, KeyEvent).

Returns
KeyEvent.DispatcherState

getSystemService

Added in API level 3
public Object getSystemService (String name)

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 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 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 ActivityManager for interacting with the global activity state of the system.
WALLPAPER_SERVICE ("wallpaper")
A 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 PowerManager for controlling power management.
ALARM_SERVICE ("alarm")
A AlarmManager for receiving intents at the time of your choosing.
NOTIFICATION_SERVICE ("notification")
A NotificationManager for informing the user of background events.
KEYGUARD_SERVICE ("keyguard")
A KeyguardManager for controlling keyguard.
LOCATION_SERVICE ("location")
A LocationManager for controlling location (e.g., GPS) updates.
SEARCH_SERVICE ("search")
A SearchManager for handling search.
VIBRATOR_MANAGER_SERVICE ("vibrator_manager")
A VibratorManager for accessing the device vibrators, interacting with individual ones and playing synchronized effects on multiple vibrators.
VIBRATOR_SERVICE ("vibrator")
A 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 UiModeManager for controlling UI modes.
DOWNLOAD_SERVICE ("download")
A DownloadManager for requesting HTTP downloads
BATTERY_SERVICE ("batterymanager")
A BatteryManager for managing battery state
JOB_SCHEDULER_SERVICE ("taskmanager")
A JobScheduler for managing scheduled tasks
NETWORK_STATS_SERVICE ("netstats")
A NetworkStatsManager for querying network usage statistics.
HARDWARE_PROPERTIES_SERVICE ("hardware_properties")
A HardwarePropertiesManager for accessing hardware properties.
DOMAIN_VERIFICATION_SERVICE ("domain_verification")
A DomainVerificationManager for accessing web domain approval state.
DISPLAY_HASH_SERVICE ("display_hash")
A 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.

Returns
Object The service or null if the name does not exist.

onBind

Added in API level 3
public final IBinder onBind (Intent intent)

Return the communication channel to the service. May return null if clients can not bind to the service. The returned IBinder is usually for a complex interface that has been described using aidl.

Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.

Parameters
intent Intent: The Intent that was used to bind to this service, as given to Context.bindService. Note that any extras that were included with the Intent at that point will not be seen here.

Returns
IBinder Return an IBinder through which clients can call on to the service.

onConfigurationChanged

Added in API level 3
public void onConfigurationChanged (Configuration configuration)

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
configuration Configuration: This value cannot be null.

onCreateInputMethodInterface

Added in API level 3
public abstract AbstractInputMethodService.AbstractInputMethodImpl onCreateInputMethodInterface ()

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

Returns
AbstractInputMethodService.AbstractInputMethodImpl

onCreateInputMethodSessionInterface

Added in API level 3
public abstract AbstractInputMethodService.AbstractInputMethodSessionImpl onCreateInputMethodSessionInterface ()

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

Returns
AbstractInputMethodService.AbstractInputMethodSessionImpl

onDestroy

Added in API level 3
public void onDestroy ()

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
public boolean onGenericMotionEvent (MotionEvent event)

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

Parameters
event MotionEvent: The motion event being received.

Returns
boolean True if the event was handled in this function, false otherwise.

onLowMemory

Added in API level 3
public void onLowMemory ()

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

onTrackballEvent

Added in API level 3
public boolean onTrackballEvent (MotionEvent event)

Implement this to handle trackball events on your input method.

Parameters
event MotionEvent: The motion event being received.

Returns
boolean True if the event was handled in this function, false otherwise.

onTrimMemory

Added in API level 14
public void onTrimMemory (int level)

Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process. You should never compare to exact values of the level, since new intermediate values may be added -- you will typically want to compare if the value is greater or equal to a level you are interested in.

To retrieve the processes current trim level at any point, you can use ActivityManager.getMyMemoryState(RunningAppProcessInfo).

Parameters
level int: The context of the trim, giving a hint of the amount of trimming the application may like to perform. Value is ComponentCallbacks2.TRIM_MEMORY_COMPLETE, ComponentCallbacks2.TRIM_MEMORY_MODERATE, ComponentCallbacks2.TRIM_MEMORY_BACKGROUND, ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN, ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL, ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW, or ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE

registerComponentCallbacks

Added in API level 14
public void registerComponentCallbacks (ComponentCallbacks callback)

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(ComponentCallbacks) 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.

unregisterComponentCallbacks

Added in API level 14
public void unregisterComponentCallbacks (ComponentCallbacks callback)

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.

Protected methods

dump

Added in API level 3
protected void dump (FileDescriptor fd, 
                PrintWriter fout, 
                String[] args)

Implement this to handle Binder.dump() calls on your input method.

Parameters
fd FileDescriptor: The raw file descriptor that the dump is being sent to.

fout PrintWriter: The PrintWriter to which you should dump your state. This will be closed for you after you return.

args String: additional arguments to the dump request.