An Input Method Editor (IME) is a control that lets users enter text. Android provides an extensible framework for input methods that allow applications to provide users with additional input methods, such as soft keyboards or voice input. Once these input methods are installed, users can select the IME they want to use from the setup of the system, and this setting is valid for the entire system, and only one input method is available at a time.
To add an input method to the Android system, you create a class application that contains the inherited Inputmethodservice class. In addition, you typically create a "settings" activity that passes the option to the IME service. You can also define a UI for the settings, and make it appear as part of the system setup.
This article contains the following elements :
1. The life cycle of the IME.
2. Declare the IME component in the application's manifest;
3. IME API
4. Design the UI for the IME
5. Send the Wenbenfal to the application from the IME
6. Use IME subtype
The life cycle of an IME
The following illustration describes the life cycle of an IME:
Figure 1. The life cycle of an IME
The following sections describe how to implement the UI and how the code is associated with this lifecycle.
Life IME component in the manifest
In Android, an IME is an Android application that contains a special IME service. The application's manifest file must declare the service, request the necessary permissions, provide a intent filter that matches the Action.view.InputMethod operation, and metadata that defines the attributes of the IME. Also, provide a setup interface that allows users to edit the IME's behavior, and you can define a "settings" activity that can be started from the system setup.
The following manifest fragment declares the IME service. It applies the Bind_input_method permission to allow the service to connect to the system's IME, establishes a intent filter that matches the Android.view.InputMethod operation, and defines the metadata for the IME:
Copy Code code as follows:
<!--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, you declare an activity for the IME to set up. It has a action_main type of intent filter, which indicates that the activity is the main entry point for an IME application:
Copy Code code as follows:
<!--Optional:an activity for controlling the IME settings-->
<activity android:name= "Fastinputimesettings"
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.