@ohos.inputMethod (Input Method Framework)

The inputMethod module is oriented to common foreground applications (third-party applications and system applications such as Notes, Messaging, and Settings). It provides input method control and management capabilities, including displaying or hiding the soft keyboard, switching between input methods, and obtaining the list of all input methods.

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. Mandatory.
id9+ string Yes No Unique ID of the input method. Mandatory.
label9+ string Yes No External display name of the input method. Optional.
icon9+ string Yes No Icon of the input method. Optional.
iconId9+ number Yes No Icon ID of the input method. Optional.
extra9+ object Yes Yes Extra information about the input method. Mandatory.
packageName(deprecated) string Yes No Name of the input method package. Mandatory.
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. Mandatory.
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 instance.

System capability: SystemCapability.MiscServices.InputMethodFramework

Return value

Type Description
InputMethodController Current InputMethodController instance.

Error codes

For details about the error codes, see Input Method Framework Error Codes.

Error Code ID Error Message
12800006 Input method controller error.

Example

let inputMethodController = inputMethod.getController();

inputMethod.getSetting9+

getSetting(): InputMethodSetting

Obtains an InputMethodSetting instance.

System capability: SystemCapability.MiscServices.InputMethodFramework

Return value

Type Description
InputMethodSetting Current InputMethodSetting instance.

Error codes

For details about the error codes, see Input Method Framework Error Codes.

Error Code ID Error Message
12800007 Input method settings extension error.

Example

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 (for system applications only)

System capability: SystemCapability.MiscServices.InputMethodFramework

Parameters

Name Type Mandatory Description
target InputMethodProperty 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.

Error Code ID Error Message
12800005 Configuration persisting error.
12800008 Input method manager service error.

Example

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));
}

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 (for system applications only)

System capability: SystemCapability.MiscServices.InputMethodFramework

Parameters

Name Type Mandatory Description
target InputMethodProperty Yes Input method to switch to.

Return value

Type Description
Promise<boolean> 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.

Error Code ID Error Message
12800005 Configuration persisting error.
12800008 Input method manager service error.

Example

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));
}

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 InputmethodProperty instance of the current input method.

Example

let currentIme = inputMethod.getCurrentInputMethod();

inputMethod.switchCurrentInputMethodSubtype9+

switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback<boolean>): 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 (for system applications only)

System capability: SystemCapability.MiscServices.InputMethodFramework

Parameters

Name Type Mandatory Description
target 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.

Error Code ID Error Message
12800005 Configuration persisting error.
12800008 Input method manager service error.

Example

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));
}

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 (for system applications only)

System capability: SystemCapability.MiscServices.InputMethodFramework

Parameters

Name Type Mandatory Description
target InputMethodSubtype Yes Input method subtype to switch to.

Return value

Type Description
Promise<boolean> 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.

Error Code ID Error Message
12800005 Configuration persisting error.
12800008 Input method manager service error.

Example

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));
}

inputMethod.getCurrentInputMethodSubtype9+

getCurrentInputMethodSubtype(): InputMethodSubtype

Obtains the current input method subtype.

System capability: SystemCapability.MiscServices.InputMethodFramework

Return value

Type Description
InputMethodSubtype Current input method subtype.

Example

let currentImeSubType = inputMethod.getCurrentInputMethodSubtype();

inputMethod.switchCurrentInputMethodAndSubtype9+

switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback<boolean>): 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 (for system applications only)

System capability: SystemCapability.MiscServices.InputMethodFramework

Parameters

Name Type Mandatory Description
inputMethodProperty InputMethodProperty Yes Input method to switch to.
inputMethodSubtype 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.

Error Code ID Error Message
12800005 Configuration persisting error.
12800008 Input method manager service error.

Example

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));
}

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 (for system applications only)

System capability: SystemCapability.MiscServices.InputMethodFramework

Parameters

Name Type Mandatory Description
inputMethodProperty InputMethodProperty Yes Input method to switch to.
inputMethodSubtype InputMethodSubtype Yes Input method subtype to switch to.

Return value

Type Description
Promise<boolean> 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.

Error Code ID Error Message
12800005 Configuration persisting error.
12800008 Input method manager service error.

Example

let im = inputMethod.getCurrentInputMethod();
let imSubType = inputMethod.getCurrentInputMethodSubtype();
try {
    inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, 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));
}

inputMethod.getInputMethodController(deprecated)

getInputMethodController(): InputMethodController

Obtains an InputMethodController instance.

NOTE

This API is supported since API version 6 and deprecated since API version 9. You are advised to use getController().

System capability: SystemCapability.MiscServices.InputMethodFramework

Return value

Type Description
InputMethodController Current InputMethodController instance.

Example

let inputMethodController = inputMethod.getInputMethodController();

inputMethod.getInputMethodSetting(deprecated)

getInputMethodSetting(): InputMethodSetting

Obtains an InputMethodSetting instance.

NOTE

This API is supported since API version 6 and deprecated since API version 9. You are advised to use getSetting().

System capability: SystemCapability.MiscServices.InputMethodFramework

Return value

Type Description
InputMethodSetting Current InputMethodSetting instance.

Example

let inputMethodSetting = inputMethod.getInputMethodSetting();

InputMethodController

In the following API examples, you must first use getController 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.

Error Code ID Error Message
12800003 Input method client error.
12800008 Input method manager service error.

Example

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));
}

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.

Error Code ID Error Message
12800003 Input method client error.
12800008 Input method manager service error.

Example

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));
}

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 (for system applications only)

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.

Error Code ID Error Message
12800003 Input method client error.
12800008 Input method manager service error.

Example

inputMethodController.showSoftKeyboard((err) => {
    if (err === undefined) {
        console.info('Succeeded in showing softKeyboard.');
    } else {
        console.error('Failed to showSoftKeyboard: ' + 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 (for system applications only)

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.

Error Code ID Error Message
12800003 Input method client error.
12800008 Input method manager service error.

Example

inputMethodController.showSoftKeyboard().then(() => {
    console.log('Succeeded in showing softKeyboard.');
}).catch((err) => {
    console.error('Failed to showSoftKeyboard: ' + 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 (for system applications only)

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.

Error Code ID Error Message
12800003 Input method client error.
12800008 Input method manager service error.

Example

inputMethodController.hideSoftKeyboard((err) => {
    if (err === undefined) {
        console.info('Succeeded in hiding softKeyboard.');
    } else {
        console.error('Failed to hideSoftKeyboard: ' + 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 (for system applications only)

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.

Error Code ID Error Message
12800003 Input method client error.
12800008 Input method manager service error.

Example

inputMethodController.hideSoftKeyboard().then(() => {
    console.log('Succeeded in hiding softKeyboard.');
}).catch((err) => {
    console.error('Failed to hideSoftKeyboard: ' + 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().

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

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(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().

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

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);
})

InputMethodSetting8+

In the following API examples, you must first use getSetting 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, inputMethodSubtype: InputMethodSubtype) => void Yes Callback used to return the input method attributes and subtype.

Example

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, inputMethodSubtype: InputMethodSubtype) => void No Callback used to return the input method attributes and subtype.

Example

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>> 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.

Error Code ID Error Message
12800001 Package manager error.
12800008 Input method manager service error.

Example

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));
}

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<Array<InputMethodSubtype>> 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.

Error Code ID Error Message
12800001 Package manager error.
12800008 Input method manager service error.

Example

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));
}

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>> 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.

Error Code ID Error Message
12800001 Package manager error.
12800008 Input method manager service error.

Example

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));
}

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<Array<InputMethodSubtype>> 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.

Error Code ID Error Message
12800001 Package manager error.
12800008 Input method manager service error.

Example

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));
}

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>> 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.

Error Code ID Error Message
12800001 Package manager error.
12800008 Input method manager service error.

Example

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));
}

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.

Error Code ID Error Message
12800001 Package manager error.
12800008 Input method manager service error.

Return value

Type Description
Promise<Array<InputMethodProperty>> Promise used to return a list of activated or deactivated input methods.

Example

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));
}

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.

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.

Error Code ID Error Message
12800008 Input method manager service error.

Example

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));
}

showOptionalInputMethods9+

showOptionalInputMethods(): Promise<boolean>

Displays a dialog box for selecting an input method. 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 operation is successful, and false means the opposite.

Error codes

For details about the error codes, see Input Method Framework Error Codes.

Error Code ID Error Message
12800008 Input method manager service error.

Example

inputMethodSetting.showOptionalInputMethods().then((data) => {
    console.info('Succeeded in showing optionalInputMethods.');
}).catch((err) => {
    console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(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.

System capability: SystemCapability.MiscServices.InputMethodFramework

Parameters

Name Type Mandatory Description
callback AsyncCallback<Array<InputMethodProperty>> Yes Callback used to return the list of installed input methods.

Example

inputMethodSetting.listInputMethod((err,data) => {
    if (err !== undefined) {
        console.error('Failed to listInputMethod: ' + JSON.stringify(err));
        return;
    }
    console.log('Succeeded in listing inputMethod.');
 });

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.

System capability: SystemCapability.MiscServices.InputMethodFramework

Return value

Type Description
Promise<Array<InputMethodProperty>> Promise used to return the list of installed input methods.

Example

inputMethodSetting.listInputMethod().then((data) => {
    console.info('Succeeded in listing inputMethod.');
}).catch((err) => {
    console.error('Failed to listInputMethod: ' + 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().

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

inputMethodSetting.displayOptionalInputMethod((err) => {
    if (err !== undefined) {
        console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
        return;
    }
    console.info('Succeeded in displaying optionalInputMethod.');
});

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().

System capability: SystemCapability.MiscServices.InputMethodFramework

Return value

Type Description
Promise<void> Promise that returns no value.

Example

inputMethodSetting.displayOptionalInputMethod().then(() => {
    console.info('Succeeded in displaying optionalInputMethod.');
}).catch((err) => {
    console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
})