# 输入法框架 本模块提供对输入法框架的管理,包括隐藏输入法、查询已安装的输入法列表和显示输入法选择对话框。 > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > > 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 ## 导入模块 ``` import inputMethod from '@ohos.inputmethod'; ``` ## inputMethod8+ 常量值。 **系统能力**:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | MAX_TYPE_NUM | number | 是 | 否 | 可支持的最大输入法个数。 | ## InputMethodProperty8+ 输入法应用属性。 **系统能力**:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | packageName(deprecated) | string | 是 | 否 | 包名。 | | methodId(deprecated) | string | 是 | 否 | Ability名。 | | name9+ | string | 是 | 否 | 包名,非必填项。 | | id9+ | string | 是 | 否 | Ability名,非必填项。 | | label9+ | string | 是 | 否 | 输入法标签,非必填项。| | icon9+ | string | 是 | 否 | 输入法图标,非必填项。 | | iconId9+ | number | 是 | 否 | 输入法图标id,非必填项。 | | extra9+ | object | 是 | 否 | 输入法其他信息,非必填项。 | ## inputMethod.getInputMethodController(deprecated) getInputMethodController(): InputMethodController 获取客户端实例[InputMethodController](#inputmethodcontroller)。 > **说明:** > 从API version 9开始废弃, 建议使用[getController](#getController)替代 > > 从 API version 6开始支持。 **系统能力**:SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | ----------------------------------------------- | ------------------------ | | [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 | **示例:** ```js var InputMethodController = inputMethod.getInputMethodController(); ``` ## inputMethod.getController9+ getController(): InputMethodController 获取客户端实例[InputMethodController](#inputmethodcontroller)。 **系统能力**:SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | ----------------------------------------------- | ------------------------ | | [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 | **示例:** ```js var InputMethodController = inputMethod.getController(); ``` ## inputMethod.getInputMethodSetting(deprecated) getInputMethodSetting(): InputMethodSetting 获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)。 > **说明:** > 从API version 9开始废弃, 建议使用[getSetting](#getSetting)替代 > > 从 API version 6开始支持。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | ----------------------------------------- | ---------------------------- | | [InputMethodSetting](#inputmethodsetting8) | 回调返回当前客户端设置实例。 | **示例:** ```js var InputMethodSetting = inputMethod.getInputMethodSetting(); ``` ## inputMethod.getSetting9+ getSetting(): InputMethodSetting 获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | ----------------------------------------- | ---------------------------- | | [InputMethodSetting](#inputmethodsetting8) | 回调返回当前客户端设置实例。 | **示例:** ```js var InputMethodSetting = inputMethod.getSetting(); ``` ## inputMethod.switchInputMethod9+ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolean>): void 切换输入法。此接口仅可在Stage模型下使用。使用callback形式返回结果。参数个数为2,否则抛出异常。 **需要权限**: ohos.permission.CONNECT_IME_ABILITY **系统能力**:SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | |target | [InputmethodProperty](#inputmethodproperty8) | 是 | 传入要切换的目标输入法。 | | callback | AsyncCallback<boolean> | 是 | 返回输入法切换是否成功。 | **示例:** ```js try{ inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard'}, (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> 切换输入法。此接口仅可在Stage模型下使用。使用promise形式返回结果。参数个数为1,否则抛出异常。 **需要权限**: ohos.permission.CONNECT_IME_ABILITY **系统能力**: SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | |target | [InputmethodProperty](#inputmethodproperty8)| 是 | 传入要切换的目标输入法。 | **返回值:** | 类型 | 说明 | | ----------------------------------------- | ---------------------------- | | Promise\ | 回调返回切换后的输入法。 | **示例:** ```js try { inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard'}).then((result) => { if (result) { console.info('Success to switchInputMethod.(promise)'); } else { console.error('Failed to switchInputMethod.(promise)'); } }).catch((err) => { console.error('switchInputMethod promise err: ' + JSON.stringify(err)); }) } catch(err) { console.error('switchInputMethod err: ' + JSON.stringify(err)); } ``` ## inputMethod.getCurrentInputMethod9+ getCurrentInputMethod(): InputMethodProperty 获取当前输入法扩展应用,提供同步接口,返回当前输入法属性对象。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | -------------------------------------------- | ------------------------ | | [InputmethodProperty](#inputmethodproperty8) | 返回当前输入法属性对象。 | **示例:** ```js var currentIme = inputMethod.getCurrentInputMethod(); ``` ## inputMethod.switchCurrentInputMethodSubtype9+ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback): void 选择当前的输入法子类型。 **需要权限**: ohos.permission.CONNECT_IME_ABILITY **系统能力**: SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | |target | [InputMethodSubtype](#InputMethodSubtype)| 是 | 传入要切换的目标输入法子类型。 | | callback | AsyncCallback<boolean> | 是 | 返回输入法子类型切换是否成功。 | **示例:** ```js let inputMethodSubProperty = { id: "com.example.kikainput", label: "ServiceExtAbility" } try { inputMethod.switchCurrentInputMethodSubtype(inputMethodSubProperty, (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> 切换输入法子类型。此接口仅可在Stage模型下使用。使用promise形式返回结果。参数个数为1,否则抛出异常。 **需要权限**: ohos.permission.CONNECT_IME_ABILITY **系统能力**: SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | |target | [InputMethodSubtype](#InputMethodSubtype)| 是 | 传入要切换的目标输入法子类型。 | **示例:** ```js let inputMethodSubProperty = { id: "com.example.kikainput", label: "ServiceExtAbility" } try { inputMethod.switchCurrentInputMethodSubtype(inputMethodSubProperty).then((result) => { if (result) { console.info('Success to switchCurrentInputMethodSubtype.(promise)'); } else { console.error('Failed to switchCurrentInputMethodSubtype.(promise)'); } }).catch((err) => { console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); }) } catch(err) { console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); } ``` ## inputMethod.getCurrentInputMethodSubtype9+ getCurrentInputMethodSubtype(): InputMethodSubtype 获取当前输入法子类型。 **需要权限**: ohos.permission.CONNECT_IME_ABILITY **系统能力**: SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | -------------------------------------------- | ------------------------ | | [InputMethodSubtype](#InputMethodSubtype) | 返回当前输入法子类型对象。 | **示例:** ```js var currentImeSubType = inputMethod.getCurrentInputMethodSubtype(); ``` ## inputMethod.switchCurrentInputMethodAndSubtype9+ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback): void 选择输入法和子类型。 **需要权限**: ohos.permission.CONNECT_IME_ABILITY **系统能力**: SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | |inputMethodProperty | [InputMethodProperty](#InputMethodProperty)| 是 | 传入要切换的目标输入法。 | |inputMethodSubtype | [inputMethodSubtype](#InputMethodSubtype)| 是 | 传入要切换的目标输入法子类型。 | | callback | AsyncCallback<boolean> | 是 | 返回输入法和子类型切换是否成功。 | **示例:** ```js let inputMethodProperty = { packageName:"com.example.kikakeyboard", methodId:"ServiceExtAbility" } let inputMethodSubProperty = { id: "com.example.kikainput", label: "ServiceExtAbility" } 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> 切换输入法子类型。此接口仅可在Stage模型下使用。使用promise形式返回结果。参数个数为1,否则抛出异常。 **需要权限**: ohos.permission.CONNECT_IME_ABILITY **系统能力**: SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | |inputMethodProperty | [InputMethodProperty](#InputMethodProperty)| 是 | 传入要切换的目标输入法。 | |inputMethodSubtype | [inputMethodSubtype](#InputMethodSubtype)| 是 | 传入要切换的目标输入法子类型。 | **示例:** ```js let inputMethodProperty = { packageName:"com.example.kikakeyboard", methodId:"ServiceExtAbility" } let inputMethodSubProperty = { id: "com.example.kikainput", label: "ServiceExtAbility" } try { inputMethod.switchCurrentInputMethodAndSubtype(property, subType).then((result) => { if (result) { console.info('Success to switchCurrentInputMethodAndSubtype.(promise)'); } else { console.error('Failed to switchCurrentInputMethodAndSubtype.(promise)'); } }).catch((err) => { console.error('switchCurrentInputMethodAndSubtype promise err: ' + err); }) } catch(err) { console.error('switchCurrentInputMethodAndSubtype promise err: ' + err); } ``` ## InputMethodController 下列API示例中都需使用[getController](#inputmethodgetcontroller)回调获取到InputMethodController实例,再通过此实例调用对应方法。 ### stopInput(deprecated) stopInput(callback: AsyncCallback<boolean>): void 隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常。 > **说明:** > 从API version 9开始废弃, 建议使用[stopInputSession](#stopInputSession)替代 > > 从 API version 6开始支持。 **系统能力**:SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | callback | AsyncCallback<boolean> | 是 | 返回输入法隐藏是否成功。 | **示例:** ```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> 隐藏输入法。使用promise形式返回结果。参数个数为0,否则抛出异常。 > **说明:** > 从API version 9开始废弃, 建议使用[stopInputSession](#stopInputSession)替代 > > 从 API version 6开始支持。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | -------- | -------- | | Promise<boolean> | 返回输入法隐藏是否成功。 | **示例:** ```js InputMethodController.stopInput().then((result) => { if (result) { console.info('Success to stopInput.(promise)'); } else { console.error('Failed to stopInput.(promise)'); } }).catch((err) => { console.error('stopInput promise err: ' + err); }) ``` ### stopInputSession9+ stopInputSession(callback: AsyncCallback<boolean>): void 隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常。 **系统能力**:SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | callback | AsyncCallback<boolean> | 是 | 返回输入法隐藏是否成功。 | **示例:** ```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)); } ``` ### stopInputSession stopInputSession(): Promise<boolean> 隐藏输入法。使用promise形式返回结果。参数个数为0,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | -------- | -------- | | Promise<boolean> | 返回输入法隐藏是否成功。 | **示例:** ```js try { InputMethodController.stopInputSession().then((result) => { if (result) { console.info('Success to stopInputSession.(promise)'); } else { console.error('Failed to stopInputSession.(promise)'); } }).catch((err) => { console.error('stopInputSession err: ' + JSON.stringify(err)); }) } catch(err) { console.error('stopInputSession err: ' + JSON.stringify(err)); } ``` ### showSoftKeyboard9+ ### showSoftKeyboard(callback: AsyncCallback<void>): void 显示软键盘,使用callback异步回调。参数个数为1,否则抛出异常。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 参数类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | 是 | 回调函数。 | **示例:** ```js InputMethodController.showSoftKeyboard((err) => { if (err === undefined) { console.info('showSoftKeyboard success'); } else { console.error('showSoftKeyboard failed because : ' + JSON.stringify(err)); } }) ``` ### showSoftKeyboard9+ ### showSoftKeyboard(): Promise<void> 显示软键盘,使用Promise异步回调。参数个数为0,否则抛出异常。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **示例:** ```js InputMethodController.showSoftKeyboard().then(async (err) => { console.log('showSoftKeyboard success'); }).catch((err) => { console.error('showSoftKeyboard promise err: ' + JSON.stringify(err)); }); ``` ### hideSoftKeyboard9+ ### hideSoftKeyboard(callback: AsyncCallback<void>): void 隐藏软键盘,使用callback异步回调。参数个数为1,否则抛出异常。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 参数类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | 是 | 回调函数。 | **示例:** ```js InputMethodController.hideSoftKeyboard((err) => { if (err === undefined) { console.info('hideSoftKeyboard success'); } else { console.error('hideSoftKeyboard failed because : ' + JSON.stringify(err)); } }) ``` ### hideSoftKeyboard9+ ### hideSoftKeyboard(): Promise<void> 隐藏软键盘,使用Promise异步回调。参数个数为0,否则抛出异常。 **系统能力:** SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **示例:** ```js InputMethodController.hideSoftKeyboard().then(async (err) => { console.log('hideSoftKeyboard success'); }).catch((err) => { console.error('hideSoftKeyboard promise err: ' + JSON.stringify(err)); }); ``` ## InputMethodSetting8+ 下列API示例中都需使用[getSetting](#inputmethodgetsetting)回调获取到InputMethodSetting实例,再通过此实例调用对应方法。 ### on('imeChange') on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void 订阅输入法及子类型变化监听事件,使用callback回调返回变化了的输入法及子类型的相关实例。参数个数为3,参数1和参数2为napi_object,参数3为napi_function,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | type | string | 是 | 设置监听类型。
-type为‘imeChange’时表示订阅输入法及子类型变化监听事件。 | | callback | [inputMethodProperty](#InputMethodProperty), [inputMethodSubtype](#InputMethodSubtype) | 是 | 回调返回输入法及子类型相关实例。 | **示例:** ```js InputMethodEngine.on('imeChange', (inputMethodProperty, inputMethodSubtype) => { InputMethodProperty = inputMethodProperty; InputMethodSubtype = inputMethodSubtype; }); ``` ### off('imeChange') on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void 取消订阅输入法及子类型变化监听事件,使用callback回调返回取消订阅的输入法及子类型的相关实例。必选参数个数为1,参数1为string,可选参数2为napi_function,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | type | string | 是 | 设置监听类型。
-type为‘imeChange’时表示取消订阅输入法及子类型变化监听事件。 | | callback | [inputMethodProperty](#InputMethodProperty), [inputMethodSubtype](#InputMethodSubtype) | 否 | 回调返回输入法及子类型相关实例。 | **示例:** ```js InputMethodAbility.off('imeChange'); ``` ### listInputMethodSubtype9+ listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback<Array<InputMethodSubtype>>): void 查询已安装的输入法子类型列表。使用callback形式返回结果。参数个数为2,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------------------------------------------------- | ---- | ---------------------- | | inputMethodProperty | InputMethodProperty| 是 | 要查询的输入法子类型的输入法属性 | callback | Array<[InputMethodSubtype](#InputMethodSubtype)> | 是 | 返回已安装输入法列表。 | **示例:** ```js let inputMethodSubProperty = { id: "com.example.kikainput", label: "ServiceExtAbility" } try { InputMethodSetting.listInputMethodSubtype(inputMethodSubProperty, (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>> 查询已安装的满足条件的输入法子类型列表。使用promise形式返回结果。参数个数为1,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | ----------------------------------------------------------- | ---------------------- | | Promise> | 返回已安装输入法子类型列表。 | **示例:** ```js let inputMethodSubProperty = { id: "com.example.kikainput", label: "ServiceExtAbility" } try { InputMethodSetting.listInputMethodSubtype(inputMethodSubProperty).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 查询当前输入法的子类型列表。使用callback形式返回结果。参数个数为1,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------------------------------------------------- | ---- | ---------------------- | | callback | Array<[InputMethodSubtype](#InputMethodSubtype)> | 是 | 返回当前输入法的子类型列表。 | **示例:** ```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>> 查询当前输入法的子类型列表。使用promise形式返回结果。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | ----------------------------------------------------------- | ---------------------- | | Promise> | 返回当前输入法的子类型列表。 | **示例:** ```js try { InputMethodSetting.listCurrentInputMethodSubtype().then((data) => { console.info('listCurrentInputMethodSubtype success'); }).catch((err) => { console.error('listCurrentInputMethodSubtype promise err: ' + err); }) } catch(err) { console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err)); } ``` ### getInputMethods9+ getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void 获取已激活/未激活输入法列表。参数enable取true,返回已激活输入法列表,取false返回未激活输入法列表。使用callback形式返回结果。参数个数为2,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | --------------------------------------------------- | ---- | ----------------------------- | | enable | boolean | 是 | 指定返回已激活/未激活。 | | callback | Array<[InputMethodProperty](#inputmethodproperty8)> | 是 | 返回已激活/未激活输入法列表。 | **示例:** ```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>> 获取已激活/未激活输入法列表。参数enable取true返回已激活输入法列表,取false返回未激活输入法列表。使用promise形式返回结果。参数个数为0,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ------- | ---- | ----------------------- | | enable | boolean | 是 | 指定返回已激活/未激活。 | **返回值:** | 类型 | 说明 | | ------------------------------------------------------------ | ----------------------------- | | Promise> | 返回已激活/未激活输入法列表。 | **示例:** ```js try { InputMethodSetting.getInputMethods(true).then((data) => { console.info('getInputMethods success'); }).catch((err) => { console.error('getInputMethods promise err: ' + JSON.stringify(err)); }) } catch(err) { console.error('getInputMethods promise err: ' + JSON.stringify(err)); } ``` ### listInputMethod(deprecated) listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void 查询已安装的输入法列表。使用callback形式返回结果。参数个数为1,否则抛出异常。 > **说明:** > 从API version 9开始废弃, 建议使用[getInputMethods](#getInputMethods)替代 > > 从 API version 8开始支持。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------------------------------------------------- | ---- | ---------------------- | | callback | Array<[InputMethodProperty](#inputmethodproperty8)> | 是 | 返回已安装输入法列表。 | **示例:** ```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>> 查询已安装的输入法列表。使用promise形式返回结果。参数个数为0,否则抛出异常。 > **说明:** > 从API version 9开始废弃, 建议使用[getInputMethods](#getInputMethods)替代 > > 从 API version 8开始支持。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | ----------------------------------------------------------- | ---------------------- | | Promise> | 返回已安装输入法列表。 | **示例:** ```js InputMethodSetting.listInputMethod().then((data) => { console.info('listInputMethod success'); }).catch((err) => { console.error('listInputMethod promise err: ' + JSON.stringify(err)); }) ``` ### displayOptionalInputMethod(deprecated) displayOptionalInputMethod(callback: AsyncCallback<void>): void 显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。 > **说明:** > 从API version 9开始废弃, 建议使用[showOptionalInputMethods](#showOptionalInputMethods)替代 > > 从 API version 8开始支持。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | callback | AsyncCallback<void> | 是 | 回调函数。 | **示例:** ```js InputMethodSetting.displayOptionalInputMethod((err) => { if (err) { console.error('displayOptionalInputMethod failed because: ' + JSON.stringify(err)); return; } console.info('displayOptionalInputMethod success'); }); ``` ### showOptionalInputMethods9+ showOptionalInputMethods(callback: AsyncCallback<void>): void 显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。 **需要权限**: ohos.permission.CONNECT_IME_ABILITY **系统能力**: SystemCapability.MiscServices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | callback | AsyncCallback<void> | 是 | 回调函数。 | **示例:** ```js try { InputMethodSetting.showOptionalInputMethods((err) => { if (err) { console.error('showOptionalInputMethods failed: ' + JSON.stringify(err)); return; } console.info('showOptionalInputMethods success'); }); } catch (err) { console.error('showOptionalInputMethods failed: ' + JSON.stringify(err)); } ``` ### displayOptionalInputMethod(deprecated) displayOptionalInputMethod(): Promise<void> 显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。 > **说明:** > 从API version 9开始废弃, 建议使用[showOptionalInputMethods](#showOptionalInputMethods)替代 > > 从 API version 8开始支持。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | -------- | -------- | | Promise<void> | 无返回结果的Promise对象。 | **示例:** ```js InputMethodSetting.displayOptionalInputMethod().then(() => { console.info('displayOptionalInputMethod success.(promise)'); }).catch((err) => { console.error('displayOptionalInputMethod promise err: ' + err); }) ``` ### showOptionalInputMethods9+ showOptionalInputMethods(): Promise<void> 显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。 **系统能力**: SystemCapability.MiscServices.InputMethodFramework **返回值:** | 类型 | 说明 | | -------- | -------- | | Promise<void> | 无返回结果的Promise对象。 | **示例:** ```js InputMethodSetting.showOptionalInputMethods().then(() => { console.info('displayOptionalInputMethod success.(promise)'); }).catch((err) => { console.error('displayOptionalInputMethod promise err: ' + err); }) ```