本模塊主要面向普通前臺應(yīng)用(備忘錄、信息、設(shè)置等系統(tǒng)應(yīng)用與三方應(yīng)用),提供對輸入法的控制、管理能力,包括顯示/隱藏輸入法軟鍵盤、切換輸入法、獲取所有輸入法列表等。
本模塊首批接口從API version 6開始支持。后續(xù)版本的新增接口,采用上角標(biāo)單獨(dú)標(biāo)記接口的起始版本。
常量值。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù)名 | 類型 | 常量值 | 說明 |
---|---|---|---|
MAX_TYPE_NUM | number | 128 | 可支持的最大輸入法個數(shù)。 |
輸入法應(yīng)用屬性。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
name9+ | string | 是 | 否 | 輸入法內(nèi)部名稱。必填。 |
id9+ | string | 是 | 否 | 輸入法唯一標(biāo)識。必填。 |
label9+ | string | 是 | 否 | 輸入法對外顯示名稱。 非必填。 |
icon9+ | string | 是 | 否 | 輸入法圖標(biāo)數(shù)據(jù)。非必填。 |
iconId9+ | number | 是 | 否 | 輸入法圖標(biāo)資源號。非必填。 |
extra9+ | object | 是 | 是 | 輸入法擴(kuò)展信息。 必填。 |
packageName(deprecated) | string | 是 | 否 | 輸入法包名。必填。 說明: 從API version 8開始支持,從API version 9開始廢棄,建議使用name替代。 |
methodId(deprecated) | string | 是 | 否 | 輸入法唯一標(biāo)識。必填。 說明: 從API version 8開始支持,從API version 9開始廢棄,建議使用id替代。 |
getController(): InputMethodController
獲取客戶端實例InputMethodController。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
回調(diào)返回當(dāng)前客戶端實例。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800006 | input method controller error. |
示例:
- let inputMethodController = inputMethod.getController();
getSetting(): InputMethodSetting
獲取客戶端設(shè)置實例InputMethodSetting。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
回調(diào)返回當(dāng)前客戶端設(shè)置實例。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800007 | input method settings extension error. |
示例:
- let inputMethodSetting = inputMethod.getSetting();
switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolean>): void
切換輸入法。使用callback異步回調(diào)。
需要權(quán)限: ohos.permission.CONNECT_IME_ABILITY,僅系統(tǒng)應(yīng)用可用。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
target | 是 | 傳入要切換的目標(biāo)輸入法。 | |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)輸入法切換成功,err為undefined,data為true;否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800005 | configuration persisting error. |
12800008 | input method manager service error. |
示例:
- let im = inputMethod.getCurrentInputMethod();
- let prop = {
- packageName: im.packageName,
- methodId: im.methodId,
- name: im.packageName,
- id: im.methodId,
- extra: {}
- }
- try{
- inputMethod.switchInputMethod(prop, (err, result) => {
- if (err !== undefined) {
- console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
- return;
- }
- if (result) {
- console.info('Succeeded in switching inputmethod.');
- } else {
- console.error('Failed to switchInputMethod.');
- }
- });
- } catch(err) {
- console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
- }
switchInputMethod(target: InputMethodProperty): Promise<boolean>
切換輸入法。使用promise異步回調(diào)。
需要權(quán)限: ohos.permission.CONNECT_IME_ABILITY,僅系統(tǒng)應(yīng)用可用。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
target | 是 | 傳入要切換的目標(biāo)輸入法。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示切換輸入法成功;返回false表示切換輸入法失敗。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800005 | configuration persisting error. |
12800008 | input method manager service error. |
示例:
- let im = inputMethod.getCurrentInputMethod();
- let prop = {
- packageName: im.packageName,
- methodId: im.methodId,
- name: im.packageName,
- id: im.methodId,
- extra: {}
- }
- try {
- inputMethod.switchInputMethod(prop).then((result) => {
- if (result) {
- console.info('Succeeded in switching inputmethod.');
- } else {
- console.error('Failed to switchInputMethod.');
- }
- }).catch((err) => {
- console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
- })
- } catch(err) {
- console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
- }
getCurrentInputMethod(): InputMethodProperty
獲取當(dāng)前輸入法擴(kuò)展應(yīng)用,提供同步接口,返回當(dāng)前輸入法屬性。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
返回當(dāng)前輸入法屬性對象。 |
示例:
- let currentIme = inputMethod.getCurrentInputMethod();
switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback<boolean>): void
在當(dāng)前輸入法應(yīng)用內(nèi)切換子類型。使用callback異步回調(diào)。
需要權(quán)限: ohos.permission.CONNECT_IME_ABILITY,僅系統(tǒng)應(yīng)用可用。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
target | 是 | 傳入要切換的目標(biāo)輸入法子類型。 | |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)輸入法子類型切換成功,err為undefined,data為true;否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800005 | configuration persisting error. |
12800008 | input method manager service error. |
示例:
- try {
- inputMethod.switchCurrentInputMethodSubtype({
- id: "ServiceExtAbility",
- label: "",
- name: "com.example.kikakeyboard",
- mode: "upper",
- locale: "",
- language: "",
- icon: "",
- iconId: 0,
- extra: {}
- }, (err, result) => {
- if (err !== undefined) {
- console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
- return;
- }
- if (result) {
- console.info('Succeeded in switching currentInputMethodSubtype.');
- } else {
- console.error('Failed to switchCurrentInputMethodSubtype');
- }
- });
- } catch(err) {
- console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
- }
switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean>
在當(dāng)前輸入法應(yīng)用內(nèi)切換子類型。使用promise異步回調(diào)。
需要權(quán)限: ohos.permission.CONNECT_IME_ABILITY,僅系統(tǒng)應(yīng)用可用。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
target | 是 | 傳入要切換的目標(biāo)輸入法子類型。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示在當(dāng)前輸入法應(yīng)用內(nèi)切換子類型成功;返回false表示在當(dāng)前輸入法應(yīng)用內(nèi)切換子類型失敗。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800005 | configuration persisting error. |
12800008 | input method manager service error. |
示例:
- try {
- inputMethod.switchCurrentInputMethodSubtype({
- id: "ServiceExtAbility",
- label: "",
- name: "com.example.kikakeyboard",
- mode: "upper",
- locale: "",
- language: "",
- icon: "",
- iconId: 0,
- extra: {}
- }).then((result) => {
- if (result) {
- console.info('Succeeded in switching currentInputMethodSubtype.');
- } else {
- console.error('Failed to switchCurrentInputMethodSubtype.');
- }
- }).catch((err) => {
- console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
- })
- } catch(err) {
- console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
- }
getCurrentInputMethodSubtype(): InputMethodSubtype
獲取當(dāng)前輸入法子類型。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
返回當(dāng)前輸入法子類型對象。 |
示例:
- let currentImeSubType = inputMethod.getCurrentInputMethodSubtype();
switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback<boolean>): void
切換至指定輸入法應(yīng)用的指定子類型,用于跨輸入法應(yīng)用切換子類型。使用callback異步回調(diào)。
需要權(quán)限: ohos.permission.CONNECT_IME_ABILITY,僅系統(tǒng)應(yīng)用可用。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
inputMethodProperty | 是 | 傳入要切換的目標(biāo)輸入法。 | |
inputMethodSubtype | 是 | 傳入要切換的目標(biāo)輸入法子類型。 | |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)輸入法和子類型切換成功,err為undefined,data為獲取到的切換子類型結(jié)果true;否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800005 | configuration persisting error. |
12800008 | input method manager service error. |
示例:
- let im = inputMethod.getCurrentInputMethod();
- let imSubType = inputMethod.getCurrentInputMethodSubtype();
- try {
- inputMethod.switchCurrentInputMethodAndSubtype(im, imSubType, (err,result) => {
- if (err !== undefined) {
- console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
- return;
- }
- if (result) {
- console.info('Succeeded in switching currentInputMethodAndSubtype.');
- } else {
- console.error('Failed to switchCurrentInputMethodAndSubtype.');
- }
- });
- } catch (err) {
- console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
- }
switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise<boolean>
切換至指定輸入法應(yīng)用的指定子類型,用于跨輸入法應(yīng)用切換子類型。使用promise異步回調(diào)。
需要權(quán)限: ohos.permission.CONNECT_IME_ABILITY,僅系統(tǒng)應(yīng)用可用。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
inputMethodProperty | 是 | 傳入要切換的目標(biāo)輸入法。 | |
inputMethodSubtype | 是 | 傳入要切換的目標(biāo)輸入法子類型。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示切換至指定輸入法應(yīng)用的指定子類型成功;返回false表示切換至指定輸入法應(yīng)用的指定子類型失敗。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800005 | configuration persisting error. |
12800008 | input method manager service error. |
示例:
- let im = inputMethod.getCurrentInputMethod();
- let imSubType = inputMethod.getCurrentInputMethodSubtype();
- try {
- inputMethod.switchCurrentInputMethodAndSubtype(im, imSubType).then((result) => {
- if (result) {
- console.info('Succeeded in switching currentInputMethodAndSubtype.');
- } else {
- console.error('Failed to switchCurrentInputMethodAndSubtype.');
- }
- }).catch((err) => {
- console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
- })
- } catch(err) {
- console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
- }
getInputMethodController(): InputMethodController
獲取客戶端實例InputMethodController。
從API version 6開始支持,從API version 9開始廢棄, 建議使用getController()替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
回調(diào)返回當(dāng)前客戶端實例。 |
示例:
- let inputMethodController = inputMethod.getInputMethodController();
getInputMethodSetting(): InputMethodSetting
獲取客戶端設(shè)置實例InputMethodSetting。
從API version 6開始支持,從API version 9開始廢棄, 建議使用getSetting()替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
回調(diào)返回當(dāng)前客戶端設(shè)置實例。 |
示例:
- let inputMethodSetting = inputMethod.getInputMethodSetting();
stopInputSession(callback: AsyncCallback<boolean>): void
結(jié)束輸入會話。通過點擊輸入框?qū)崿F(xiàn)輸入會話的開啟之后該接口的調(diào)用才可生效。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)結(jié)束輸入會話成功時,err為undefined,data為true;否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
12800008 | input method manager service error. |
示例:
- try {
- inputMethodController.stopInputSession((error, result) => {
- if (error !== undefined) {
- console.error('Failed to stopInputSession: ' + JSON.stringify(error));
- return;
- }
- if (result) {
- console.info('Succeeded in stopping inputSession.');
- } else {
- console.error('Failed to stopInputSession.');
- }
- });
- } catch(error) {
- console.error('Failed to stopInputSession: ' + JSON.stringify(error));
- }
stopInputSession(): Promise<boolean>
結(jié)束輸入會話。通過點擊輸入框?qū)崿F(xiàn)輸入會話的開啟之后此接口才可生效。使用promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示結(jié)束輸入會話成功;返回false表示結(jié)束輸入會話失敗。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
12800008 | input method manager service error. |
示例:
- try {
- inputMethodController.stopInputSession().then((result) => {
- if (result) {
- console.info('Succeeded in stopping inputSession.');
- } else {
- console.error('Failed to stopInputSession.');
- }
- }).catch((err) => {
- console.error('Failed to stopInputSession: ' + JSON.stringify(err));
- })
- } catch(err) {
- console.error('Failed to stopInputSession: ' + JSON.stringify(err));
- }
showSoftKeyboard(callback: AsyncCallback<void>): void
顯示軟鍵盤。需要與輸入框綁定使用。當(dāng)點擊輸入框后,才可通過該接口的調(diào)用顯示出當(dāng)前輸入法的軟鍵盤。使用callback異步回調(diào)。
需要權(quán)限: ohos.permission.CONNECT_IME_ABILITY,僅系統(tǒng)應(yīng)用可用。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)軟鍵盤顯示成功。err為undefined,否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
12800008 | input method manager service error. |
示例:
- inputMethodController.showSoftKeyboard((err) => {
- if (err === undefined) {
- console.info('Succeeded in showing softKeyboard.');
- } else {
- console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err));
- }
- })
showSoftKeyboard(): Promise<void>
顯示軟鍵盤。需要與輸入框綁定使用。當(dāng)點擊輸入框后,才可通過該接口的調(diào)用顯示出當(dāng)前輸入法的軟鍵盤。使用Promise異步回調(diào)。
需要權(quán)限: ohos.permission.CONNECT_IME_ABILITY,僅系統(tǒng)應(yīng)用可用。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
12800008 | input method manager service error. |
示例:
- inputMethodController.showSoftKeyboard().then(() => {
- console.log('Succeeded in showing softKeyboard.');
- }).catch((err) => {
- console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err));
- });
hideSoftKeyboard(callback: AsyncCallback<void>): void
隱藏軟鍵盤。需要與輸入框綁定使用。點擊輸入框后,才可以使用該接口的調(diào)用隱藏軟鍵盤。使用callback異步回調(diào)。
需要權(quán)限: ohos.permission.CONNECT_IME_ABILITY,僅系統(tǒng)應(yīng)用可用。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)軟鍵盤隱藏成功。err為undefined,否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
12800008 | input method manager service error. |
示例:
- inputMethodController.hideSoftKeyboard((err) => {
- if (err === undefined) {
- console.info('Succeeded in hiding softKeyboard.');
- } else {
- console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err));
- }
- })
hideSoftKeyboard(): Promise<void>
隱藏軟鍵盤。需要與輸入框綁定使用。點擊輸入框后,才可以使用該接口的調(diào)用隱藏軟鍵盤。使用Promise異步回調(diào)。
需要權(quán)限: ohos.permission.CONNECT_IME_ABILITY,僅系統(tǒng)應(yīng)用可用。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
12800008 | input method manager service error. |
示例:
- inputMethodController.hideSoftKeyboard().then(() => {
- console.log('Succeeded in hiding softKeyboard.');
- }).catch((err) => {
- console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err));
- });
stopInput(callback: AsyncCallback<boolean>): void
結(jié)束輸入會話。通過點擊輸入框?qū)崿F(xiàn)輸入會話的開啟之后該接口的調(diào)用才可生效。使用callback異步回調(diào)。
從API version 6開始支持,從API version 9開始廢棄, 建議使用stopInputSession()替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)輸入法隱藏成功,err為undefined,data為true;否則為錯誤對象。 |
示例:
- inputMethodController.stopInput((error, result) => {
- if (error !== undefined) {
- console.error('Failed to stopInput: ' + JSON.stringify(error));
- return;
- }
- if (result) {
- console.info('Succeeded in stopping input.');
- } else {
- console.error('Failed to stopInput.');
- }
- });
stopInput(): Promise<boolean>
結(jié)束輸入會話。通過點擊輸入框?qū)崿F(xiàn)輸入會話的開啟之后該接口的調(diào)用才可生效。使用promise異步回調(diào)。
從API version 6開始支持,從API version 9開始廢棄, 建議使用stopInputSession()替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示輸入法隱藏成功;返回false表示輸入法隱藏失敗。 |
示例:
- inputMethodController.stopInput().then((result) => {
- if (result) {
- console.info('Succeeded in stopping input.');
- } else {
- console.error('Failed to stopInput.');
- }
- }).catch((err) => {
- console.error('Failed to stopInput: ' + err);
- })
on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void
訂閱輸入法及子類型變化監(jiān)聽事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 -type為‘imeChange’時表示訂閱輸入法及子類型變化監(jiān)聽事件。 |
callback | (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void | 是 | 回調(diào)函數(shù),返回輸入法屬性對象及輸入法子類型對象。 |
示例:
- inputMethodSetting.on('imeChange', (inputMethodProperty, inputMethodSubtype) => {
- console.info('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype));
- });
off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void
取消訂閱輸入法及子類型變化監(jiān)聽事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 -type為‘imeChange’時表示取消訂閱輸入法及子類型變化監(jiān)聽事件。 |
callback | (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void | 否 | 回調(diào)函數(shù),返回取消訂閱的輸入法屬性對象及輸入法子類型對象。 |
示例:
- inputMethodSetting.off('imeChange');
listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback<Array<InputMethodSubtype>>): void
獲取指定輸入法應(yīng)用的所有子類型。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
inputMethodProperty | InputMethodProperty | 是 | 子類型所屬的輸入法應(yīng)用。 |
callback | AsyncCallback<Array<InputMethodSubtype>> | 是 | 回調(diào)函數(shù),返回指定輸入法應(yīng)用的所有子類型。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800001 | package manager error. |
12800008 | input method manager service error. |
示例:
- let inputMethodProperty = {
- packageName: 'com.example.kikakeyboard',
- methodId: 'com.example.kikakeyboard',
- name: 'com.example.kikakeyboard',
- id: 'com.example.kikakeyboard',
- extra:{}
- }
- try {
- inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => {
- if (err !== undefined) {
- console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
- return;
- }
- console.log('Succeeded in listing inputMethodSubtype.');
- });
- } catch (err) {
- console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
- }
listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise<Array<InputMethodSubtype>>
獲取指定輸入法應(yīng)用的所有子類型。使用promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
inputMethodProperty | InputMethodProperty | 是 | 子類型所屬的輸入法應(yīng)用。 |
返回值:
類型 | 說明 |
---|---|
Promise<Array<InputMethodSubtype>> | Promise對象,返回指定輸入法應(yīng)用的所有子類型。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800001 | package manager error. |
12800008 | input method manager service error. |
示例:
- let inputMethodProperty = {
- packageName: 'com.example.kikakeyboard',
- methodId: 'com.example.kikakeyboard',
- name: 'com.example.kikakeyboard',
- id: 'com.example.kikakeyboard',
- extra:{}
- }
- try {
- inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => {
- console.info('Succeeded in listing inputMethodSubtype.');
- }).catch((err) => {
- console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
- })
- } catch(err) {
- console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
- }
listCurrentInputMethodSubtype(callback: AsyncCallback<Array<InputMethodSubtype>>): void
查詢當(dāng)前輸入法應(yīng)用的所有子類型。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<Array<InputMethodSubtype>> | 是 | 回調(diào)函數(shù),返回當(dāng)前輸入法應(yīng)用的所有子類型。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800001 | package manager error. |
12800008 | input method manager service error. |
示例:
- try {
- inputMethodSetting.listCurrentInputMethodSubtype((err, data) => {
- if (err !== undefined) {
- console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
- return;
- }
- console.log('Succeeded in listing currentInputMethodSubtype.');
- });
- } catch(err) {
- console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
- }
listCurrentInputMethodSubtype(): Promise<Array<InputMethodSubtype>>
查詢當(dāng)前輸入法的子類型列表。使用promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<Array<InputMethodSubtype>> | Promise對象,返回當(dāng)前輸入法應(yīng)用的所有子類型。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800001 | package manager error. |
12800008 | input method manager service error. |
示例:
- try {
- inputMethodSetting.listCurrentInputMethodSubtype().then((data) => {
- console.info('Succeeded in listing currentInputMethodSubtype.');
- }).catch((err) => {
- console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
- })
- } catch(err) {
- console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
- }
getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void
獲取已激活/未激活輸入法列表。參數(shù)enable取true,返回已激活輸入法列表,取false返回未激活輸入法列表。已激活/未激活輸入法的確切功能當(dāng)前版本未支持。當(dāng)前版本中,已激活輸入法包括當(dāng)前使用的輸入法,未激活輸入法包括當(dāng)前輸入法以外的其他已安裝的輸入法。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
enable | boolean | 是 | 指定返回已激活/未激活。 |
callback | AsyncCallback<Array<InputMethodProperty>> | 是 | 回調(diào)函數(shù),返回已激活/未激活輸入法列表。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800001 | package manager error. |
12800008 | input method manager service error. |
示例:
- try {
- inputMethodSetting.getInputMethods(true, (err,data) => {
- if (err !== undefined) {
- console.error('Failed to getInputMethods: ' + JSON.stringify(err));
- return;
- }
- console.log('Succeeded in getting inputMethods.');
- });
- } catch (err) {
- console.error('Failed to getInputMethods: ' + JSON.stringify(err));
- }
getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>>
獲取已激活/未激活輸入法列表。參數(shù)enable取true,返回已激活輸入法列表,取false返回未激活輸入法列表。已激活/未激活輸入法的確切功能當(dāng)前版本未支持。當(dāng)前版本中,已激活輸入法包括當(dāng)前使用的輸入法,未激活輸入法包括當(dāng)前輸入法以外的其他已安裝的輸入法。使用promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
enable | boolean | 是 | 指定返回已激活/未激活。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800001 | package manager error. |
12800008 | input method manager service error. |
返回值:
類型 | 說明 |
---|---|
Promise<Array<InputMethodProperty>> | Promise對象,返回已激活/未激活輸入法列表。 |
示例:
- try {
- inputMethodSetting.getInputMethods(true).then((data) => {
- console.info('Succeeded in getting inputMethods.');
- }).catch((err) => {
- console.error('Failed to getInputMethods: ' + JSON.stringify(err));
- })
- } catch(err) {
- console.error('Failed to getInputMethods: ' + JSON.stringify(err));
- }
showOptionalInputMethods(callback: AsyncCallback<boolean>): void
顯示輸入法選擇對話框。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)輸入法選擇對話框顯示成功,err為undefined,data為true;否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800008 | input method manager service error. |
示例:
- try {
- inputMethodSetting.showOptionalInputMethods((err, data) => {
- if (err !== undefined) {
- console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in showing optionalInputMethods.');
- });
- } catch (err) {
- console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
- }
showOptionalInputMethods(): Promise<boolean>
顯示輸入法選擇對話框。使用promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示輸入法選擇對話框顯示成功;返回false表示輸入法選擇對話框顯示失敗。 |
錯誤碼:
以下錯誤碼的詳細(xì)介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800008 | input method manager service error. |
示例:
- inputMethodSetting.showOptionalInputMethods().then((data) => {
- console.info('Succeeded in showing optionalInputMethods.');
- }).catch((err) => {
- console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
- })
listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void
查詢已安裝的輸入法列表。使用callback異步回調(diào)。
從API version 8開始支持,從API version 9開始廢棄, 建議使用getInputMethods替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<Array<InputMethodProperty>> | 是 | 回調(diào)函數(shù),返回已安裝的輸入法列表。 |
示例:
- inputMethodSetting.listInputMethod((err,data) => {
- if (err !== undefined) {
- console.error('Failed to listInputMethod: ' + JSON.stringify(err));
- return;
- }
- console.log('Succeeded in listing inputMethod.');
- });
listInputMethod(): Promise<Array<InputMethodProperty>>
查詢已安裝的輸入法列表。使用promise異步回調(diào)。
從API version 8開始支持,從API version 9開始廢棄, 建議使用getInputMethods替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<Array<InputMethodProperty>> | Promise對象,返回已安裝輸入法列表。 |
示例:
- inputMethodSetting.listInputMethod().then((data) => {
- console.info('Succeeded in listing inputMethod.');
- }).catch((err) => {
- console.error('Failed to listInputMethod: ' + JSON.stringify(err));
- })
displayOptionalInputMethod(callback: AsyncCallback<void>): void
顯示輸入法選擇對話框。使用callback異步回調(diào)。
從API version 8開始支持,從API version 9開始廢棄, 建議使用showOptionalInputMethods()替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)輸入法選擇對話框顯示成功。err為undefined,否則為錯誤對象。 |
示例:
- inputMethodSetting.displayOptionalInputMethod((err) => {
- if (err !== undefined) {
- console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in displaying optionalInputMethod.');
- });
displayOptionalInputMethod(): Promise<void>
顯示輸入法選擇對話框。使用promise異步回調(diào)。
從API version 8開始支持,從API version 9開始廢棄, 建議使用showOptionalInputMethods()替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- inputMethodSetting.displayOptionalInputMethod().then(() => {
- console.info('Succeeded in displaying optionalInputMethod.');
- }).catch((err) => {
- console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
- })
更多建議: