The Input Method Editor (IME) is a control that allows users to input text. Android provides an extensible Input Method framework that allows applications to provide users with additional input methods, such as soft keyboard or voice input. Once these input methods are installed, you can select the ime they want from the system settings, and this setting is valid for the entire system, each time only one input method is available.
To add an Input Method to the Android system, you must create a class application that inherits the inputmethodservice class. In addition, you usually need to create a "Settings" activity to pass the options to the ime service. You can also define a UI for setting and display it as part of the system setting.
This article includes the following content:
1. Ime lifecycle.
2. Declare the ime component in the Application List;
3. Ime API
4. design the ime UI
5. Send text from IME to the application
6. Use the ime subtype
IME Lifecycle
Describes the ime lifecycle:
Figure 1. Ime Lifecycle
The following sections describe how to implement the UI and how code is associated with this lifecycle.
IME components in the list
In the Android system, IME is an android application that contains special IME services. The application inventory file must declare the service, apply for necessary permissions, provide intent filters that match the action. View. inputmethod operation, and define the metadata of IME features. In addition, a setting interface is provided to allow users to use it to edit IME behaviors. You can define a "Settings" activity that can be started from system settings.
The following list snippet declares the ime service. It applies for the bind_input_method permission to allow services to connect to the system's IME, creates an intent filter that matches the Android. View. inputmethod operation, and defines metadata for IME:
<! -- Declares the input method service -->
<Service android: Name = "fastinputime"
Android: Label = "@ string/fast_input_label"
Android: Permission = "android. Permission. bind_input_method">
<Intent-filter>
<Action Android: Name = "android. View. inputmethod"/>
</Intent-filter>
<Meta-data Android: Name = "android. View. Im" Android: Resource = "@ XML/method"/>
</Service>
Next, I declare the activity for setting to ime. It has an intent filter of the action_main type, which indicates that the activity is the main entry of the ime application:
<! -- Optional: An activity for controlling the ime settings -->
<Activity Android: Name = "fastinputimesetask"
Android: Label = "@ string/fast_input_settings">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
</Intent-filter>
</Activity>
You can also provide direct access to IME settings in the UI of this setting.