# Input Method Framework The **inputMethod** module provides an input method framework, which can be used to hide the keyboard, obtain the list of installed input methods, display the dialog box for input method selection, and more. >**NOTE** > >The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import ``` import inputMethod from '@ohos.inputmethod'; ``` ## Constants8+ Provides the constants. **System capability**: SystemCapability.MiscServices.InputMethodFramework | Name| Type| Value| Description| | -------- | -------- | -------- | -------- | | MAX_TYPE_NUM | number | 128 | Maximum number of supported input methods.| ## InputMethodProperty8+ Describes the input method application attributes. **System capability**: SystemCapability.MiscServices.InputMethodFramework | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | | name9+ | string | Yes| No| Internal name of the input method.| | id9+ | string | Yes| No| Unique ID of the input method.| | label9+ | string | Yes| No| External display name of the input method.| | icon9+ | string | Yes| No| Icon of the input method.| | iconId9+ | number | Yes| No| Icon ID of the input method.| | extra9+ | object | Yes| No| Extra information about the input method.| | packageName(deprecated) | string | Yes| No| Name of the input method package.
**NOTE**
This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name**.| | methodId(deprecated) | string | Yes| No| Unique ID of the input method.
**NOTE**
This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id**.| ## inputMethod.getController9+ getController(): InputMethodController Obtains an **[InputMethodController](#inputmethodcontroller)** instance. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------------- | ------------------------ | | [InputMethodController](#inputmethodcontroller) | Current **InputMethodController** instance.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | ------------------------------ | | 12800006 | Input method controller error. | **Example** ```js let inputMethodController = inputMethod.getController(); ``` ## inputMethod.getSetting9+ getSetting(): InputMethodSetting Obtains an **[InputMethodSetting](#inputmethodsetting8)** instance. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------- | ---------------------------- | | [InputMethodSetting](#inputmethodsetting8) | Current **InputMethodSetting** instance.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800007 | Input method settings extension error. | **Example** ```js let inputMethodSetting = inputMethod.getSetting(); ``` ## inputMethod.switchInputMethod9+ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolean>): void Switches to another input method. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | target | [InputMethodProperty](#inputmethodproperty8) | Yes| Input method to switch to.| | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object. | **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | | 12800008 | Input method settings extension error. | **Example** ```js try{ inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}, (err, result) => { if (err) { console.error('switchInputMethod err: ' + JSON.stringify(err)); return; } if (result) { console.info('Success to switchInputMethod.(callback)'); } else { console.error('Failed to switchInputMethod.(callback)'); } }); } catch(err) { console.error('switchInputMethod err: ' + JSON.stringify(err)); } ``` ## inputMethod.switchInputMethod9+ switchInputMethod(target: InputMethodProperty): Promise<boolean> Switches to another input method. This API uses a promise to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | |target | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.| **Return value** | Type | Description | | ----------------------------------------- | ---------------------------- | | Promise\ | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | | 12800008 | Input method settings extension error. | **Example** ```js try { inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}).then((result) => { if (result) { console.info('Success to switchInputMethod.'); } else { console.error('Failed to switchInputMethod.'); } }).catch((err) => { console.error('switchInputMethod err: ' + JSON.stringify(err)); }) } catch(err) { console.error('switchInputMethod err: ' + JSON.stringify(err)); } ``` ## inputMethod.getCurrentInputMethod9+ getCurrentInputMethod(): InputMethodProperty Obtains the current input method. This API synchronously returns the **InputmethodProperty** instance of the current input method. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | -------------------------------------------- | ------------------------ | | [InputMethodProperty](#inputmethodproperty8) | **InputmethodProperty** instance of the current input method.| **Example** ```js let currentIme = inputMethod.getCurrentInputMethod(); ``` ## inputMethod.switchCurrentInputMethodSubtype9+ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback\): void Switches to another subtype of the current input method. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | target | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.| | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object. | **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | | 12800008 | Input method settings extension error. | **Example** ```js let inputMethodSubtype = { id: "com.example.kikakeyboard", label: "ServiceExtAbility", name: "", mode: "upper", locale: "", language: "", icon: "", iconId: 0, extra: {} } try { inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype, (err, result) => { if (err) { console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); return; } if (result) { console.info('Success to switchCurrentInputMethodSubtype.(callback)'); } else { console.error('Failed to switchCurrentInputMethodSubtype.(callback)'); } }); } catch(err) { console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); } ``` ## inputMethod.switchCurrentInputMethodSubtype9+ switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean> Switches to another subtype of the current input method. This API uses a promise to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | |target | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.| **Return value** | Type | Description | | ----------------------------------------- | ---------------------------- | | Promise\ | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | | 12800008 | Input method settings extension error. | **Example** ```js let inputMethodSubtype = { id: "com.example.kikakeyboard", label: "ServiceExtAbility", name: "", mode: "upper", locale: "", language: "", icon: "", iconId: 0, extra: {} } try { inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype).then((result) => { if (result) { console.info('Success to switchCurrentInputMethodSubtype.'); } else { console.error('Failed to switchCurrentInputMethodSubtype.'); } }).catch((err) => { console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); }) } catch(err) { console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); } ``` ## inputMethod.getCurrentInputMethodSubtype9+ getCurrentInputMethodSubtype(): InputMethodSubtype Obtains the current input method subtype. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | -------------------------------------------- | ------------------------ | | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype) | Current input method subtype.| **Example** ```js let currentImeSubType = inputMethod.getCurrentInputMethodSubtype(); ``` ## inputMethod.switchCurrentInputMethodAndSubtype9+ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback\): void Switches to a specified subtype of a specified input method. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | |inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.| |inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.| | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object. | **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | | 12800008 | Input method settings extension error. | **Example** ```js let inputMethodProperty = { packageName: "com.example.kikakeyboard", methodId: "ServiceExtAbility", extra: {} } let inputMethodSubProperty = { id: "com.example.kikakeyboard", label: "ServiceExtAbility", name: "", mode: "upper", locale: "", language: "", icon: "", iconId: 0, extra: {} } try { inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty, (err,result) => { if (err) { console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err)); return; } if (result) { console.info('Success to switchCurrentInputMethodAndSubtype.(callback)'); } else { console.error('Failed to switchCurrentInputMethodAndSubtype.(callback)'); } }); } catch (err) { console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err)); } ``` ## inputMethod.switchCurrentInputMethodAndSubtype9+ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise<boolean> Switches to a specified subtype of a specified input method. This API uses a promise to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | |inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.| |inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.| **Return value** | Type | Description | | ----------------------------------------- | ---------------------------- | | Promise\ | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | | 12800008 | Input method settings extension error. | **Example** ```js let inputMethodProperty = { packageName: "com.example.kikakeyboard", methodId: "ServiceExtAbility", extra: {} } let inputMethodSubProperty = { id: "com.example.kikakeyboard", label: "ServiceExtAbility", name: "", mode: "upper", locale: "", language: "", icon: "", iconId: 0, extra: {} } try { inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty).then((result) => { if (result) { console.info('Success to switchCurrentInputMethodAndSubtype.'); } else { console.error('Failed to switchCurrentInputMethodAndSubtype.'); } }).catch((err) => { console.error('switchCurrentInputMethodAndSubtype err: ' + err); }) } catch(err) { console.error('switchCurrentInputMethodAndSubtype err: ' + err); } ``` ## inputMethod.getInputMethodController(deprecated) getInputMethodController(): InputMethodController Obtains an **[InputMethodController](#inputmethodcontroller)** instance. > **NOTE** > > This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getController()](#inputmethodgetcontroller9). **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------------- | ------------------------ | | [InputMethodController](#inputmethodcontroller) | Current **InputMethodController** instance.| **Example** ```js let inputMethodController = inputMethod.getInputMethodController(); ``` ## inputMethod.getInputMethodSetting(deprecated) getInputMethodSetting(): InputMethodSetting Obtains an **[InputMethodSetting](#inputmethodsetting8)** instance. > **NOTE** > > This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getSetting()](#inputmethodgetsetting9). **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------- | ---------------------------- | | [InputMethodSetting](#inputmethodsetting8) | Current **InputMethodSetting** instance.| **Example** ```js let inputMethodSetting = inputMethod.getInputMethodSetting(); ``` ## InputMethodController In the following API examples, you must first use [getController](#inputmethodgetcontroller9) to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance. ### stopInputSession9+ stopInputSession(callback: AsyncCallback<boolean>): void Ends this input session. The invoking of this API takes effect only after the input session is enabled by clicking the text box. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object. | **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | | 12800008 | Input method settings extension error. | **Example** ```js try { inputMethodController.stopInputSession((error, result) => { if (error) { console.error('stopInputSession err: ' + JSON.stringify(error)); return; } if (result) { console.info('Success to stopInputSession.(callback)'); } else { console.error('Failed to stopInputSession.(callback)'); } }); } catch(error) { console.error('stopInputSession err: ' + JSON.stringify(error)); } ``` ### stopInputSession9+ stopInputSession(): Promise<boolean> Ends this input session. The invoking of this API takes effect only after the input session is enabled by clicking the text box. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type| Description| | -------- | -------- | | Promise<boolean> | Promise used to return the result. The value **true** means that the ending is successful, and **false** means the opposite.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | | 12800008 | Input method settings extension error. | **Example** ```js try { inputMethodController.stopInputSession().then((result) => { if (result) { console.info('Success to stopInputSession.'); } else { console.error('Failed to stopInputSession.'); } }).catch((err) => { console.error('stopInputSession err: ' + JSON.stringify(err)); }) } catch(err) { console.error('stopInputSession err: ' + JSON.stringify(err)); } ``` ### showSoftKeyboard9+ showSoftKeyboard(callback: AsyncCallback<void>): void Shows this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | | 12800008 | Input method settings extension error. | **Example** ```js inputMethodController.showSoftKeyboard((err) => { if (err === undefined) { console.info('showSoftKeyboard success'); } else { console.error('showSoftKeyboard failed because : ' + JSON.stringify(err)); } }) ``` ### showSoftKeyboard9+ showSoftKeyboard(): Promise<void> Shows this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses a promise to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | | 12800008 | Input method settings extension error. | **Example** ```js inputMethodController.showSoftKeyboard().then(async (err) => { console.log('showSoftKeyboard success'); }).catch((err) => { console.error('showSoftKeyboard err: ' + JSON.stringify(err)); }); ``` ### hideSoftKeyboard9+ hideSoftKeyboard(callback: AsyncCallback<void>): void Hides this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | | 12800008 | Input method settings extension error. | **Example** ```js inputMethodController.hideSoftKeyboard((err) => { if (err === undefined) { console.info('hideSoftKeyboard success'); } else { console.error('hideSoftKeyboard failed because : ' + JSON.stringify(err)); } }) ``` ### hideSoftKeyboard9+ hideSoftKeyboard(): Promise<void> Hides this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses a promise to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | | 12800008 | Input method settings extension error. | **Example** ```js inputMethodController.hideSoftKeyboard().then(async (err) => { console.log('hideSoftKeyboard success'); }).catch((err) => { console.error('hideSoftKeyboard err: ' + JSON.stringify(err)); }); ``` ### stopInput(deprecated) stopInput(callback: AsyncCallback<boolean>): void Ends this input session. The invoking of this API takes effect only after the input session is enabled by clicking the text box. This API uses an asynchronous callback to return the result. > **NOTE** > > This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9). **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object. | **Example** ```js inputMethodController.stopInput((error, result) => { if (error) { console.error('failed to stopInput because: ' + JSON.stringify(error)); return; } if (result) { console.info('Success to stopInput.(callback)'); } else { console.error('Failed to stopInput.(callback)'); } }); ``` ### stopInput(deprecated) stopInput(): Promise<boolean> Ends this input session. The invoking of this API takes effect only after the input session is enabled by clicking the text box. This API uses a promise to return the result. > **NOTE** > > This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9). **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type| Description| | -------- | -------- | | Promise<boolean> | Promise used to return the result. The value **true** means that the hiding is successful, and **false** means the opposite.| **Example** ```js inputMethodController.stopInput().then((result) => { if (result) { console.info('Success to stopInput.'); } else { console.error('Failed to stopInput.'); } }).catch((err) => { console.error('stopInput err: ' + err); }) ``` ## InputMethodSetting8+ In the following API examples, you must first use [getSetting](#inputmethodgetsetting9) to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance. ### on('imeChange')9+ on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void Enables listening for the input method and subtype change event. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type.
The value **'imeChange'** indicates the input method and subtype change event.| | callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void | Yes| Callback used to return the input method attributes and subtype.| **Example** ```js inputMethodSetting.on('imeChange', (inputMethodProperty, inputMethodSubtype) => { console.info('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype)); }); ``` ### off('imeChange')9+ off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void Disables listening for the input method and subtype change event. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type.
The value **'imeChange'** indicates the input method and subtype change event.| | callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void | No| Callback used to return the input method attributes and subtype.| **Example** ```js inputMethodSetting.off('imeChange'); ``` ### listInputMethodSubtype9+ listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback<Array<InputMethodSubtype>>): void Obtains all subtypes of a specified input method. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------- | ---- | ---------------------- | | inputMethodProperty | InputMethodProperty| Yes| Input method to which the subtypes belong.| | callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Yes| Callback used to return all subtypes of the specified input method.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | | 12800008 | Input method settings extension error. | **Example** ```js let inputMethodProperty = { packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra:{} } try { inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => { if (err) { console.error('listInputMethodSubtype failed: ' + JSON.stringify(err)); return; } console.log('listInputMethodSubtype success'); }); } catch (err) { console.error('listInputMethodSubtype failed: ' + JSON.stringify(err)); } ``` ### listInputMethodSubtype9+ listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise<Array<InputMethodSubtype>> Obtains all subtypes of a specified input method. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------- | ---- | ---------------------- | | inputMethodProperty | InputMethodProperty| Yes| Input method to which the subtypes belong.| **Return value** | Type | Description | | ----------------------------------------------------------- | ---------------------- | | Promise> | Promise used to return all subtypes of the specified input method.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | | 12800008 | Input method settings extension error. | **Example** ```js let inputMethodProperty = { packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra:{} } try { inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => { console.info('listInputMethodSubtype success'); }).catch((err) => { console.error('listInputMethodSubtype err: ' + JSON.stringify(err)); }) } catch(err) { console.error('listInputMethodSubtype err: ' + JSON.stringify(err)); } ``` ### listCurrentInputMethodSubtype9+ listCurrentInputMethodSubtype(callback: AsyncCallback<Array<InputMethodSubtype>>): void Obtains all subtypes of this input method. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------- | ---- | ---------------------- | | callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Yes | Callback used to return all subtypes of the current input method.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | | 12800008 | Input method settings extension error. | **Example** ```js try { inputMethodSetting.listCurrentInputMethodSubtype((err, data) => { if (err) { console.error('listCurrentInputMethodSubtype failed: ' + JSON.stringify(err)); return; } console.log('listCurrentInputMethodSubtype success'); }); } catch(err) { console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err)); } ``` ### listCurrentInputMethodSubtype9+ listCurrentInputMethodSubtype(): Promise<Array<InputMethodSubtype>> Obtains all subtypes of this input method. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------------------------- | ---------------------- | | Promise> | Promise used to return all subtypes of the current input method.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | | 12800008 | Input method settings extension error. | **Example** ```js try { inputMethodSetting.listCurrentInputMethodSubtype().then((data) => { console.info('listCurrentInputMethodSubtype success'); }).catch((err) => { console.error('listCurrentInputMethodSubtype err: ' + err); }) } catch(err) { console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err)); } ``` ### getInputMethods9+ getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void Obtains a list of activated or deactivated input methods. In the current version, an activated input method is the input method in use, and a deactivated one is any of the installed input methods except the one in use. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------------------------------------- | ---- | ----------------------------- | | enable | boolean | Yes | Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods. | | callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | Yes | Callback used to return a list of activated or deactivated input methods.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | | 12800008 | Input method settings extension error. | **Example** ```js try { inputMethodSetting.getInputMethods(true, (err,data) => { if (err) { console.error('getInputMethods failed: ' + JSON.stringify(err)); return; } console.log('getInputMethods success'); }); } catch (err) { console.error('getInputMethods failed: ' + JSON.stringify(err)); } ``` ### getInputMethods9+ getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>> Obtains a list of activated or deactivated input methods. In the current version, an activated input method is the input method in use, and a deactivated one is any of the installed input methods except the one in use. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type | Mandatory| Description | | ------ | ------- | ---- | ----------------------- | | enable | boolean | Yes | Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | | 12800008 | Input method settings extension error. | **Return value** | Type | Description | | ------------------------------------------------------------ | ----------------------------- | | Promise> | Promise used to return a list of activated or deactivated input methods.| **Example** ```js try { inputMethodSetting.getInputMethods(true).then((data) => { console.info('getInputMethods success'); }).catch((err) => { console.error('getInputMethods err: ' + JSON.stringify(err)); }) } catch(err) { console.error('getInputMethods err: ' + JSON.stringify(err)); } ``` ### showOptionalInputMethods9+ showOptionalInputMethods(callback: AsyncCallback<boolean>): void Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object. | **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800008 | Input method settings extension error. | **Example** ```js try { inputMethodSetting.showOptionalInputMethods((err, data) => { if (err) { console.error('showOptionalInputMethods failed: ' + JSON.stringify(err)); return; } console.info('showOptionalInputMethods success'); }); } catch (err) { console.error('showOptionalInputMethods failed: ' + JSON.stringify(err)); } ``` ### showOptionalInputMethods9+ showOptionalInputMethods(): Promise<boolean> Displays a dialog box for selecting an input method. This API uses a promise to return the result. **Required permissions**: ohos.permission.CONNECT_IME_ABILITY **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type| Description| | -------- | -------- | | Promise<boolean> | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.| **Error codes** For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800008 | Input method settings extension error. | **Example** ```js inputMethodSetting.showOptionalInputMethods().then((data) => { console.info('displayOptionalInputMethod success.'); }).catch((err) => { console.error('displayOptionalInputMethod err: ' + err); }) ``` ### listInputMethod(deprecated) listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void Obtains a list of installed input methods. This API uses an asynchronous callback to return the result. > **NOTE** > > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethods](#getinputmethods9). **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------- | ---- | ---------------------- | | callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | Yes | Callback used to return the list of installed input methods.| **Example** ```js inputMethodSetting.listInputMethod((err,data) => { if (err) { console.error('listInputMethod failed because: ' + JSON.stringify(err)); return; } console.log('listInputMethod success'); }); ``` ### listInputMethod(deprecated) listInputMethod(): Promise<Array<InputMethodProperty>> Obtains a list of installed input methods. This API uses a promise to return the result. > **NOTE** > > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethods](#getinputmethods9-1). **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type | Description | | ----------------------------------------------------------- | ---------------------- | | Promise> | Promise used to return the list of installed input methods.| **Example** ```js inputMethodSetting.listInputMethod().then((data) => { console.info('listInputMethod success'); }).catch((err) => { console.error('listInputMethod err: ' + JSON.stringify(err)); }) ``` ### displayOptionalInputMethod(deprecated) displayOptionalInputMethod(callback: AsyncCallback<void>): void Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. > **NOTE** > > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [showOptionalInputMethods()](#showoptionalinputmethods9). **System capability**: SystemCapability.MiscServices.InputMethodFramework **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | **Example** ```js inputMethodSetting.displayOptionalInputMethod((err) => { if (err) { console.error('displayOptionalInputMethod failed because: ' + JSON.stringify(err)); return; } console.info('displayOptionalInputMethod success'); }); ``` ### displayOptionalInputMethod(deprecated) displayOptionalInputMethod(): Promise<void> Displays a dialog box for selecting an input method. This API uses a promise to return the result. > **NOTE** > > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [showOptionalInputMethods()](#showoptionalinputmethods9-1). **System capability**: SystemCapability.MiscServices.InputMethodFramework **Return value** | Type| Description| | -------- | -------- | | Promise<void> | Promise that returns no value.| **Example** ```js inputMethodSetting.displayOptionalInputMethod().then(() => { console.info('displayOptionalInputMethod success'); }).catch((err) => { console.error('displayOptionalInputMethod err: ' + err); }) ```