js-apis-inputmethod.md 52.1 KB
Newer Older
E
ester.zhou 已提交
1
# @ohos.inputMethod (Input Method Framework)
E
ester.zhou 已提交
2

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

E
ester.zhou 已提交
5
> **NOTE**
E
ester.zhou 已提交
6
>
E
ester.zhou 已提交
7
> 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.
E
ester.zhou 已提交
8 9 10 11


## Modules to Import

E
ester.zhou 已提交
12
```js
E
ester.zhou 已提交
13
import inputMethod from '@ohos.inputMethod';
E
ester.zhou 已提交
14 15
```

E
ester.zhou 已提交
16
## Constants<sup>8+</sup>
E
ester.zhou 已提交
17 18 19

Provides the constants.

20
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
21

E
ester.zhou 已提交
22 23 24
| Name| Type| Value| Description|
| -------- | -------- | -------- | -------- |
| MAX_TYPE_NUM | number | 128 | Maximum number of supported input methods.|
E
ester.zhou 已提交
25

E
ester.zhou 已提交
26
## InputMethodProperty<sup>8+</sup>
E
ester.zhou 已提交
27 28 29

Describes the input method application attributes.

30
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
31 32 33

| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
34 35 36 37 38 39 40 41
| name<sup>9+</sup>  | string | Yes| No| Internal name of the input method. Mandatory.|
| id<sup>9+</sup>    | string | Yes| No| Unique ID of the input method. Mandatory.|
| label<sup>9+</sup>    | string | Yes| No| External display name of the input method. Optional.|
| icon<sup>9+</sup>    | string | Yes| No| Icon of the input method. Optional.|
| iconId<sup>9+</sup>    | number | Yes| No| Icon ID of the input method. Optional.|
| extra<sup>9+</sup>    | object | Yes| Yes| Extra information about the input method. Mandatory.|
| packageName<sup>(deprecated)</sup> | string | Yes| No| Name of the input method package. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name**.|
| methodId<sup>(deprecated)</sup> | string | Yes| No| Unique ID of the input method. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id**.|
E
ester.zhou 已提交
42

E
ester.zhou 已提交
43
## inputMethod.getController<sup>9+</sup>
E
ester.zhou 已提交
44

E
ester.zhou 已提交
45
getController(): InputMethodController
E
ester.zhou 已提交
46

47
Obtains an **[InputMethodController](#inputmethodcontroller)** instance.
E
ester.zhou 已提交
48

49
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
50

E
ester.zhou 已提交
51
**Return value**
E
ester.zhou 已提交
52

E
ester.zhou 已提交
53 54
| Type                                           | Description                    |
| ----------------------------------------------- | ------------------------ |
E
ester.zhou 已提交
55
| [InputMethodController](#inputmethodcontroller) | Current **InputMethodController** instance.|
E
ester.zhou 已提交
56

E
ester.zhou 已提交
57 58 59 60 61 62 63 64
**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. |

E
ester.zhou 已提交
65 66
**Example**

E
ester.zhou 已提交
67
```js
E
ester.zhou 已提交
68
let inputMethodController = inputMethod.getController();
E
ester.zhou 已提交
69
```
E
ester.zhou 已提交
70

E
ester.zhou 已提交
71
## inputMethod.getSetting<sup>9+</sup>
E
ester.zhou 已提交
72

E
ester.zhou 已提交
73
getSetting(): InputMethodSetting
E
ester.zhou 已提交
74

75
Obtains an **[InputMethodSetting](#inputmethodsetting8)** instance.
E
ester.zhou 已提交
76

77
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
78

E
ester.zhou 已提交
79
**Return value**
E
ester.zhou 已提交
80

E
ester.zhou 已提交
81 82
| Type                                     | Description                        |
| ----------------------------------------- | ---------------------------- |
E
ester.zhou 已提交
83
| [InputMethodSetting](#inputmethodsetting8) | Current **InputMethodSetting** instance.|
84

E
ester.zhou 已提交
85 86 87 88 89 90 91
**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. |
E
ester.zhou 已提交
92

E
ester.zhou 已提交
93
**Example**
E
ester.zhou 已提交
94

E
ester.zhou 已提交
95
```js
E
ester.zhou 已提交
96
let inputMethodSetting = inputMethod.getSetting();
E
ester.zhou 已提交
97
```
E
ester.zhou 已提交
98

99 100
## inputMethod.switchInputMethod<sup>9+</sup>

E
ester.zhou 已提交
101
switchInputMethod(target: InputMethodProperty, callback: AsyncCallback&lt;boolean&gt;): void
102

E
ester.zhou 已提交
103 104
Switches to another input method. This API uses an asynchronous callback to return the result.

E
ester.zhou 已提交
105
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
106 107 108 109 110 111 112

**System capability**: SystemCapability.MiscServices.InputMethodFramework

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
113
| target | [InputMethodProperty](#inputmethodproperty8) | Yes| Input method to switch to.|
E
ester.zhou 已提交
114
| callback | AsyncCallback&lt;boolean&gt; | 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.|
E
ester.zhou 已提交
115 116

**Error codes**
117

E
ester.zhou 已提交
118 119 120 121 122
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.        |
E
ester.zhou 已提交
123
| 12800008 | Input method manager service error. |
124 125 126 127

**Example**

```js
E
ester.zhou 已提交
128 129 130 131 132 133 134 135
let im = inputMethod.getCurrentInputMethod();
let prop = {
    packageName: im.packageName,
    methodId: im.methodId,
    name: im.packageName,
    id: im.methodId,
    extra: {}
}
E
ester.zhou 已提交
136
try{
E
ester.zhou 已提交
137 138 139
    inputMethod.switchInputMethod(prop, (err, result) => {
        if (err !== undefined) {
            console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
E
ester.zhou 已提交
140 141 142
            return;
        }
        if (result) {
E
ester.zhou 已提交
143
            console.info('Succeeded in switching inputmethod.');
E
ester.zhou 已提交
144
        } else {
E
ester.zhou 已提交
145
            console.error('Failed to switchInputMethod.');
E
ester.zhou 已提交
146 147 148
        }
    });
} catch(err) {
E
ester.zhou 已提交
149
    console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
E
ester.zhou 已提交
150
}
151 152
```
## inputMethod.switchInputMethod<sup>9+</sup>
E
ester.zhou 已提交
153
switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt;
154

E
ester.zhou 已提交
155 156
Switches to another input method. This API uses a promise to return the result.

E
ester.zhou 已提交
157
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
E
ester.zhou 已提交
158

159 160 161 162
**System capability**: SystemCapability.MiscServices.InputMethodFramework

**Parameters**

E
ester.zhou 已提交
163 164 165
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  |target |  [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.|
166 167

**Return value**
E
ester.zhou 已提交
168

E
ester.zhou 已提交
169 170 171
  | Type                                     | Description                        |
  | ----------------------------------------- | ---------------------------- |
  | Promise\<boolean> | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.|
172

E
ester.zhou 已提交
173
**Error codes**
174

E
ester.zhou 已提交
175 176 177 178 179
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.        |
E
ester.zhou 已提交
180
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
181 182

**Example**
183 184

```js
E
ester.zhou 已提交
185 186 187 188 189 190 191 192
let im = inputMethod.getCurrentInputMethod();
let prop = {
    packageName: im.packageName,
    methodId: im.methodId,
    name: im.packageName,
    id: im.methodId,
    extra: {}
}
E
ester.zhou 已提交
193
try {
E
ester.zhou 已提交
194
    inputMethod.switchInputMethod(prop).then((result) => {
E
ester.zhou 已提交
195
        if (result) {
E
ester.zhou 已提交
196
            console.info('Succeeded in switching inputmethod.');
E
ester.zhou 已提交
197 198 199 200
        } else {
            console.error('Failed to switchInputMethod.');
        }
    }).catch((err) => {
E
ester.zhou 已提交
201
        console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
E
ester.zhou 已提交
202 203
    })
} catch(err) {
E
ester.zhou 已提交
204
    console.error('Failed to switchInputMethod: ' + JSON.stringify(err));
E
ester.zhou 已提交
205
}
E
ester.zhou 已提交
206
```
E
ester.zhou 已提交
207

E
ester.zhou 已提交
208 209 210 211 212 213 214 215 216 217 218 219
## inputMethod.getCurrentInputMethod<sup>9+</sup>

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                    |
| -------------------------------------------- | ------------------------ |
E
ester.zhou 已提交
220
| [InputMethodProperty](#inputmethodproperty8) | **InputmethodProperty** instance of the current input method.|
E
ester.zhou 已提交
221 222 223

**Example**

E
ester.zhou 已提交
224 225 226 227 228 229 230 231 232 233
```js
let currentIme = inputMethod.getCurrentInputMethod();
```

## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>

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.

E
ester.zhou 已提交
234
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
E
ester.zhou 已提交
235 236 237 238 239 240 241 242

**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.|
E
ester.zhou 已提交
243
| callback | AsyncCallback&lt;boolean&gt; | 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.|
E
ester.zhou 已提交
244 245 246 247 248 249 250 251

**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.        |
E
ester.zhou 已提交
252
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
253 254

**Example**
E
ester.zhou 已提交
255 256

```js
E
ester.zhou 已提交
257
try {
E
ester.zhou 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270
    inputMethod.switchCurrentInputMethodSubtype({
      id: "com.example.kikakeyboard",
      label: "ServiceExtAbility",
      name: "",
      mode: "upper",
      locale: "",
      language: "",
      icon: "",
      iconId: 0,
      extra: {}
    }, (err, result) => {
        if (err !== undefined) {
            console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
271 272 273
            return;
        }
        if (result) {
E
ester.zhou 已提交
274
            console.info('Succeeded in switching currentInputMethodSubtype.');
E
ester.zhou 已提交
275
        } else {
E
ester.zhou 已提交
276
            console.error('Failed to switchCurrentInputMethodSubtype');
E
ester.zhou 已提交
277 278 279
        }
    });
} catch(err) {
E
ester.zhou 已提交
280
    console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
281 282 283 284 285 286 287 288 289
}
```

## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>

switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise&lt;boolean&gt;

Switches to another subtype of the current input method. This API uses a promise to return the result.

E
ester.zhou 已提交
290
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
E
ester.zhou 已提交
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312

**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\<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](../errorcodes/errorcode-inputmethod-framework.md).

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
E
ester.zhou 已提交
313
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
314 315 316 317 318

**Example**

```js
try {
E
ester.zhou 已提交
319 320 321 322 323 324 325 326 327 328 329
    inputMethod.switchCurrentInputMethodSubtype({
      id: "com.example.kikakeyboard",
      label: "ServiceExtAbility",
      name: "",
      mode: "upper",
      locale: "",
      language: "",
      icon: "",
      iconId: 0,
      extra: {}
    }).then((result) => {
E
ester.zhou 已提交
330
        if (result) {
E
ester.zhou 已提交
331
            console.info('Succeeded in switching currentInputMethodSubtype.');
E
ester.zhou 已提交
332 333 334 335
        } else {
            console.error('Failed to switchCurrentInputMethodSubtype.');
        }
    }).catch((err) => {
E
ester.zhou 已提交
336
        console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
337 338
    })
} catch(err) {
E
ester.zhou 已提交
339
    console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
}
```

## inputMethod.getCurrentInputMethodSubtype<sup>9+</sup>

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.switchCurrentInputMethodAndSubtype<sup>9+</sup>

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.

E
ester.zhou 已提交
369
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
E
ester.zhou 已提交
370 371 372 373 374 375 376 377 378

**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.|
E
ester.zhou 已提交
379
| callback | AsyncCallback&lt;boolean&gt; | 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.|
E
ester.zhou 已提交
380 381 382 383 384 385 386 387

**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.        |
E
ester.zhou 已提交
388
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
389 390 391 392

**Example**

```js
E
ester.zhou 已提交
393
let im = inputMethod.getCurrentInputMethod();
E
ester.zhou 已提交
394
let inputMethodProperty = {
E
ester.zhou 已提交
395 396 397 398
    packageName: im.packageName,
    methodId: im.methodId,
    name: im.packageName,
    id: im.methodId,
E
ester.zhou 已提交
399 400 401
    extra: {}
}
try {
E
ester.zhou 已提交
402 403 404 405 406 407 408 409 410 411 412 413 414
    inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, {
      id: "com.example.kikakeyboard",
      label: "ServiceExtAbility",
      name: "",
      mode: "upper",
      locale: "",
      language: "",
      icon: "",
      iconId: 0,
      extra: {}
    }, (err,result) => {
        if (err !== undefined) {
            console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
415 416 417
            return;
        }
        if (result) {
E
ester.zhou 已提交
418
            console.info('Succeeded in switching currentInputMethodAndSubtype.');
E
ester.zhou 已提交
419
        } else {
E
ester.zhou 已提交
420
            console.error('Failed to switchCurrentInputMethodAndSubtype.');
E
ester.zhou 已提交
421 422 423
        }
    });
} catch (err) {
E
ester.zhou 已提交
424
    console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
425 426 427 428 429 430 431 432 433
}
```

## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>

switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise&lt;boolean&gt;

Switches to a specified subtype of a specified input method. This API uses a promise to return the result.

E
ester.zhou 已提交
434
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
E
ester.zhou 已提交
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457

**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\<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](../errorcodes/errorcode-inputmethod-framework.md).

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
E
ester.zhou 已提交
458
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
459 460 461 462

**Example**

```js
E
ester.zhou 已提交
463
let im = inputMethod.getCurrentInputMethod();
E
ester.zhou 已提交
464
let inputMethodProperty = {
E
ester.zhou 已提交
465 466 467 468
    packageName: im.packageName,
    methodId: im.methodId,
    name: im.packageName,
    id: im.methodId,
E
ester.zhou 已提交
469 470 471
    extra: {}
}
try {
E
ester.zhou 已提交
472 473 474 475 476 477 478 479 480 481 482
    inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, {
      id: im.packageName,
      label: im.methodId,
      name: "",
      mode: "upper",
      locale: "",
      language: "",
      icon: "",
      iconId: 0,
      extra: {}
    }).then((result) => {
E
ester.zhou 已提交
483
        if (result) {
E
ester.zhou 已提交
484
            console.info('Succeeded in switching currentInputMethodAndSubtype.');
E
ester.zhou 已提交
485 486 487 488
        } else {
            console.error('Failed to switchCurrentInputMethodAndSubtype.');
        }
    }).catch((err) => {
E
ester.zhou 已提交
489
        console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
490 491
    })
} catch(err) {
E
ester.zhou 已提交
492
    console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
}
```

## inputMethod.getInputMethodController<sup>(deprecated)</sup>

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<sup>(deprecated)</sup>

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();
542
```
E
ester.zhou 已提交
543

E
ester.zhou 已提交
544
## InputMethodController
E
ester.zhou 已提交
545

E
ester.zhou 已提交
546
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.
E
ester.zhou 已提交
547

E
ester.zhou 已提交
548
### stopInputSession<sup>9+</sup>
E
ester.zhou 已提交
549

E
ester.zhou 已提交
550
stopInputSession(callback: AsyncCallback&lt;boolean&gt;): void
E
ester.zhou 已提交
551

E
ester.zhou 已提交
552
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.
E
ester.zhou 已提交
553

554
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
555

E
ester.zhou 已提交
556
**Parameters**
E
ester.zhou 已提交
557

E
ester.zhou 已提交
558 559
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
560
| callback | AsyncCallback&lt;boolean&gt; | 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.|
E
ester.zhou 已提交
561 562 563 564 565 566 567 568

**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.             |
E
ester.zhou 已提交
569
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
570

E
ester.zhou 已提交
571
**Example**
E
ester.zhou 已提交
572

E
ester.zhou 已提交
573
```js
E
ester.zhou 已提交
574 575
try {
    inputMethodController.stopInputSession((error, result) => {
E
ester.zhou 已提交
576 577
        if (error !== undefined) {
            console.error('Failed to stopInputSession: ' + JSON.stringify(error));
E
ester.zhou 已提交
578 579 580
            return;
        }
        if (result) {
E
ester.zhou 已提交
581
            console.info('Succeeded in stopping inputSession.');
E
ester.zhou 已提交
582
        } else {
E
ester.zhou 已提交
583
            console.error('Failed to stopInputSession.');
E
ester.zhou 已提交
584 585 586
        }
    });
} catch(error) {
E
ester.zhou 已提交
587
    console.error('Failed to stopInputSession: ' + JSON.stringify(error));
E
ester.zhou 已提交
588
}
E
ester.zhou 已提交
589 590
```

E
ester.zhou 已提交
591
### stopInputSession<sup>9+</sup>
E
ester.zhou 已提交
592

E
ester.zhou 已提交
593
stopInputSession(): Promise&lt;boolean&gt;
E
ester.zhou 已提交
594

E
ester.zhou 已提交
595
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.
E
ester.zhou 已提交
596

597
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
598

E
ester.zhou 已提交
599
**Return value**
E
ester.zhou 已提交
600

E
ester.zhou 已提交
601 602
| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
603
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the ending is successful, and **false** means the opposite.|
E
ester.zhou 已提交
604

E
ester.zhou 已提交
605 606 607
**Error codes**

For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
E
ester.zhou 已提交
608

E
ester.zhou 已提交
609 610 611
| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
E
ester.zhou 已提交
612
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
613 614

**Example**
E
ester.zhou 已提交
615

E
ester.zhou 已提交
616
```js
E
ester.zhou 已提交
617 618 619
try {
    inputMethodController.stopInputSession().then((result) => {
        if (result) {
E
ester.zhou 已提交
620
            console.info('Succeeded in stopping inputSession.');
E
ester.zhou 已提交
621 622 623 624
        } else {
            console.error('Failed to stopInputSession.');
        }
    }).catch((err) => {
E
ester.zhou 已提交
625
        console.error('Failed to stopInputSession: ' + JSON.stringify(err));
E
ester.zhou 已提交
626 627
    })
} catch(err) {
E
ester.zhou 已提交
628
    console.error('Failed to stopInputSession: ' + JSON.stringify(err));
E
ester.zhou 已提交
629
}
E
ester.zhou 已提交
630 631
```

E
ester.zhou 已提交
632
### showSoftKeyboard<sup>9+</sup>
E
ester.zhou 已提交
633 634 635

showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void

E
ester.zhou 已提交
636 637
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.

E
ester.zhou 已提交
638
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
E
ester.zhou 已提交
639 640 641 642 643 644 645

**System capability**: SystemCapability.MiscServices.InputMethodFramework

**Parameters**

| Name  | Type                 | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
E
ester.zhou 已提交
646
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
E
ester.zhou 已提交
647 648 649 650 651 652 653 654

**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.             |
E
ester.zhou 已提交
655
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
656 657 658 659

**Example**

```js
E
ester.zhou 已提交
660
inputMethodController.showSoftKeyboard((err) => {
E
ester.zhou 已提交
661
    if (err === undefined) {
E
ester.zhou 已提交
662
        console.info('Succeeded in showing softKeyboard.');
E
ester.zhou 已提交
663
    } else {
E
ester.zhou 已提交
664
        console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err));
E
ester.zhou 已提交
665 666 667 668
    }
})
```

E
ester.zhou 已提交
669
### showSoftKeyboard<sup>9+</sup>
E
ester.zhou 已提交
670 671 672

showSoftKeyboard(): Promise&lt;void&gt;

E
ester.zhou 已提交
673 674
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.

E
ester.zhou 已提交
675
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
E
ester.zhou 已提交
676 677 678 679 680 681 682 683 684

**System capability**: SystemCapability.MiscServices.InputMethodFramework

**Return value**

| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

E
ester.zhou 已提交
685 686 687 688 689 690 691
**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.             |
E
ester.zhou 已提交
692
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
693

E
ester.zhou 已提交
694 695 696
**Example**

```js
E
ester.zhou 已提交
697 698
inputMethodController.showSoftKeyboard().then(() => {
    console.log('Succeeded in showing softKeyboard.');
E
ester.zhou 已提交
699
}).catch((err) => {
E
ester.zhou 已提交
700
    console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err));
E
ester.zhou 已提交
701 702 703
});
```

E
ester.zhou 已提交
704
### hideSoftKeyboard<sup>9+</sup>
E
ester.zhou 已提交
705 706 707

hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void

E
ester.zhou 已提交
708 709
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.

E
ester.zhou 已提交
710
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
E
ester.zhou 已提交
711 712 713 714 715 716 717

**System capability**: SystemCapability.MiscServices.InputMethodFramework

**Parameters**

| Name  | Type                 | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
E
ester.zhou 已提交
718
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
E
ester.zhou 已提交
719 720 721 722 723 724 725 726

**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.             |
E
ester.zhou 已提交
727
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
728 729 730 731

**Example**

```js
E
ester.zhou 已提交
732
inputMethodController.hideSoftKeyboard((err) => {
E
ester.zhou 已提交
733
    if (err === undefined) {
E
ester.zhou 已提交
734
        console.info('Succeeded in hiding softKeyboard.');
E
ester.zhou 已提交
735
    } else {
E
ester.zhou 已提交
736
        console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err));
E
ester.zhou 已提交
737 738 739 740
    }
})
```

E
ester.zhou 已提交
741
### hideSoftKeyboard<sup>9+</sup>
E
ester.zhou 已提交
742 743 744

hideSoftKeyboard(): Promise&lt;void&gt;

E
ester.zhou 已提交
745 746
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.

E
ester.zhou 已提交
747
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
E
ester.zhou 已提交
748 749 750 751 752 753 754 755 756

**System capability**: SystemCapability.MiscServices.InputMethodFramework

**Return value**

| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

E
ester.zhou 已提交
757 758 759 760 761 762 763
**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.             |
E
ester.zhou 已提交
764
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
765

E
ester.zhou 已提交
766 767 768
**Example**

```js
E
ester.zhou 已提交
769 770
inputMethodController.hideSoftKeyboard().then(() => {
    console.log('Succeeded in hiding softKeyboard.');
E
ester.zhou 已提交
771
}).catch((err) => {
E
ester.zhou 已提交
772
    console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err));
E
ester.zhou 已提交
773
});
E
ester.zhou 已提交
774 775
```

E
ester.zhou 已提交
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
### stopInput<sup>(deprecated)</sup>

stopInput(callback: AsyncCallback&lt;boolean&gt;): 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|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
792
| callback | AsyncCallback&lt;boolean&gt; | 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.|
E
ester.zhou 已提交
793 794 795 796 797

**Example**

```js
inputMethodController.stopInput((error, result) => {
E
ester.zhou 已提交
798 799
    if (error !== undefined) {
        console.error('Failed to stopInput: ' + JSON.stringify(error));
E
ester.zhou 已提交
800 801 802
        return;
    }
    if (result) {
E
ester.zhou 已提交
803
        console.info('Succeeded in stopping input.');
E
ester.zhou 已提交
804
    } else {
E
ester.zhou 已提交
805
        console.error('Failed to stopInput.');
E
ester.zhou 已提交
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
    }
});
```

### stopInput<sup>(deprecated)</sup>

stopInput(): Promise&lt;boolean&gt;

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&lt;boolean&gt; | 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) {
E
ester.zhou 已提交
833
        console.info('Succeeded in stopping input.');
E
ester.zhou 已提交
834 835 836 837
    } else {
        console.error('Failed to stopInput.');
    }
}).catch((err) => {
E
ester.zhou 已提交
838
    console.error('Failed to stopInput: ' + err);
E
ester.zhou 已提交
839 840 841
})
```

E
ester.zhou 已提交
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
### on('selectByRange')<sup>10+</sup>

on(type: 'selectByRange', callback: Callback&lt;Range&gt;): void

Enables listening for the selection-by-range 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.<br>The value **selectByRange** indicates the selection-by-range event.|
| callback | Callback&lt;[Range](./js-apis-inputmethod-InputMethodCommon.md#range)&gt; | Yes  | Callback used to return the range of the text to be selected.<br>Your application needs to select the text in the returned range in the text box.|

**Example**

```js
inputMethodController.on('selectByRange', (range) => {
    console.info('Succeeded in subscribing selectByRange: start: ' + range.start + " , end: " + range.end);
});
```

### off('selectByRange')<sup>10+</sup>

off(type: 'selectByRange'): void

Disables listening for the selection-by-range event.

**System capability**: SystemCapability.MiscServices.InputMethodFramework

**Parameters**

| Name| Type  | Mandatory| Description                                                        |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| type   | string | Yes  | Listening type.<br>The value **selectByRange** indicates the selection-by-range event.|

**Example**

```js
inputMethodController.off('selectByRange');
```

### on('selectByMovement')<sup>10+</sup>

E
ester.zhou 已提交
887
on(type: 'selectByMovement', callback: Callback&lt;Movement&gt;): void
E
ester.zhou 已提交
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927

Enables listening for the selection-by-cursor-movement 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.<br>The value **selectByMovement** indicates the selection-by-cursor-movement event.|
| callback | Callback&lt;[Movement](./js-apis-inputmethod-InputMethodCommon.md#movement)&gt; | Yes  | Callback used to return the range of the text to be selected.<br>Your application needs to select the text in the returned range in the text box.|

**Example**

```js
inputMethodController.on('selectByMovement', (movement) => {
    console.info('Succeeded in subscribing selectByMovement: direction: ' + movement.direction);
});
```

### off('selectByMovement')<sup>10+</sup>

off(type: 'selectByMovement'): void

Disables listening for the selection-by-cursor-movement event.

**System capability**: SystemCapability.MiscServices.InputMethodFramework

**Parameters**

| Name| Type  | Mandatory| Description                                                        |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| type   | string | Yes  | Listening type.<br>The value **selectByMovement** indicates the selection-by-cursor-movement event.|

**Example**

```js
inputMethodController.off('selectByMovement');
```

E
ester.zhou 已提交
928
## InputMethodSetting<sup>8+</sup>
E
ester.zhou 已提交
929

E
ester.zhou 已提交
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
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')<sup>9+</sup>

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.<br>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')<sup>9+</sup>

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.<br>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');
```

### listInputMethodSubtype<sup>9+</sup>

listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): 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&lt;Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>&gt; | 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.                 |
E
ester.zhou 已提交
998
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
999 1000 1001 1002 1003

**Example**

```js
let inputMethodProperty = {
E
ester.zhou 已提交
1004 1005 1006 1007
    packageName: 'com.example.kikakeyboard',
    methodId: 'com.example.kikakeyboard',
    name: 'com.example.kikakeyboard',
    id: 'com.example.kikakeyboard',
E
ester.zhou 已提交
1008 1009 1010 1011
    extra:{}
}
try {
    inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => {
E
ester.zhou 已提交
1012 1013
        if (err !== undefined) {
            console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
1014 1015
            return;
        }
E
ester.zhou 已提交
1016
        console.log('Succeeded in listing inputMethodSubtype.');
E
ester.zhou 已提交
1017 1018
    });
} catch (err) {
E
ester.zhou 已提交
1019
    console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
}
```

### listInputMethodSubtype<sup>9+</sup>

listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;

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](./js-apis-inputmethod-subtype.md#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](../errorcodes/errorcode-inputmethod-framework.md).

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
E
ester.zhou 已提交
1050
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
1051 1052 1053 1054 1055

**Example**

```js
let inputMethodProperty = {
E
ester.zhou 已提交
1056 1057 1058 1059
    packageName: 'com.example.kikakeyboard',
    methodId: 'com.example.kikakeyboard',
    name: 'com.example.kikakeyboard',
    id: 'com.example.kikakeyboard',
E
ester.zhou 已提交
1060 1061 1062 1063
    extra:{}
}
try {
    inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => {
E
ester.zhou 已提交
1064
        console.info('Succeeded in listing inputMethodSubtype.');
E
ester.zhou 已提交
1065
    }).catch((err) => {
E
ester.zhou 已提交
1066
        console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
1067 1068
    })
} catch(err) {
E
ester.zhou 已提交
1069
    console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
}
```

### listCurrentInputMethodSubtype<sup>9+</sup>

listCurrentInputMethodSubtype(callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): 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&lt;Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>&gt; | 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.                 |
E
ester.zhou 已提交
1094
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
1095 1096 1097 1098 1099 1100

**Example**

```js
try {
    inputMethodSetting.listCurrentInputMethodSubtype((err, data) => {
E
ester.zhou 已提交
1101 1102
        if (err !== undefined) {
            console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
1103 1104
            return;
        }
E
ester.zhou 已提交
1105
        console.log('Succeeded in listing currentInputMethodSubtype.');
E
ester.zhou 已提交
1106 1107
    });
} catch(err) {
E
ester.zhou 已提交
1108
    console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
1109 1110
}
```
E
ester.zhou 已提交
1111

E
ester.zhou 已提交
1112
### listCurrentInputMethodSubtype<sup>9+</sup>
E
ester.zhou 已提交
1113

E
ester.zhou 已提交
1114
listCurrentInputMethodSubtype(): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;
E
ester.zhou 已提交
1115

E
ester.zhou 已提交
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
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](./js-apis-inputmethod-subtype.md#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](../errorcodes/errorcode-inputmethod-framework.md).

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
E
ester.zhou 已提交
1133
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
1134 1135 1136 1137 1138 1139

**Example**

```js
try {
    inputMethodSetting.listCurrentInputMethodSubtype().then((data) => {
E
ester.zhou 已提交
1140
        console.info('Succeeded in listing currentInputMethodSubtype.');
E
ester.zhou 已提交
1141
    }).catch((err) => {
E
ester.zhou 已提交
1142
        console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
1143 1144
    })
} catch(err) {
E
ester.zhou 已提交
1145
    console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
1146 1147 1148 1149 1150 1151 1152 1153
}
```

### getInputMethods<sup>9+</sup>

getInputMethods(enable: boolean, callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): 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.
E
ester.zhou 已提交
1154 1155 1156 1157 1158 1159 1160 1161

**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.      |
E
ester.zhou 已提交
1162 1163 1164 1165 1166 1167 1168 1169 1170
| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; | 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.                 |
E
ester.zhou 已提交
1171
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
1172 1173 1174 1175

**Example**

```js
E
ester.zhou 已提交
1176 1177
try {
    inputMethodSetting.getInputMethods(true, (err,data) => {
E
ester.zhou 已提交
1178 1179
        if (err !== undefined) {
            console.error('Failed to getInputMethods: ' + JSON.stringify(err));
E
ester.zhou 已提交
1180 1181
            return;
        }
E
ester.zhou 已提交
1182
        console.log('Succeeded in getting inputMethods.');
E
ester.zhou 已提交
1183 1184
    });
} catch (err) {
E
ester.zhou 已提交
1185
    console.error('Failed to getInputMethods: ' + JSON.stringify(err));
E
ester.zhou 已提交
1186
}
E
ester.zhou 已提交
1187 1188
```

E
ester.zhou 已提交
1189
### getInputMethods<sup>9+</sup>
E
ester.zhou 已提交
1190

E
ester.zhou 已提交
1191
getInputMethods(enable: boolean): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
E
ester.zhou 已提交
1192

E
ester.zhou 已提交
1193
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.
E
ester.zhou 已提交
1194 1195 1196 1197 1198 1199 1200 1201 1202

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

E
ester.zhou 已提交
1203 1204 1205 1206 1207 1208 1209
**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.                 |
E
ester.zhou 已提交
1210
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
1211

E
ester.zhou 已提交
1212 1213 1214 1215
**Return value**

| Type                                                        | Description                         |
| ------------------------------------------------------------ | ----------------------------- |
E
ester.zhou 已提交
1216
| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return a list of activated or deactivated input methods.|
E
ester.zhou 已提交
1217 1218 1219 1220

**Example**

```js
E
ester.zhou 已提交
1221 1222
try {
    inputMethodSetting.getInputMethods(true).then((data) => {
E
ester.zhou 已提交
1223
        console.info('Succeeded in getting inputMethods.');
E
ester.zhou 已提交
1224
    }).catch((err) => {
E
ester.zhou 已提交
1225
        console.error('Failed to getInputMethods: ' + JSON.stringify(err));
E
ester.zhou 已提交
1226 1227
    })
} catch(err) {
E
ester.zhou 已提交
1228
    console.error('Failed to getInputMethods: ' + JSON.stringify(err));
E
ester.zhou 已提交
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243
}
```

### showOptionalInputMethods<sup>9+</sup>

showOptionalInputMethods(callback: AsyncCallback&lt;boolean&gt;): 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|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1244
| callback | AsyncCallback&lt;boolean&gt; | 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.|
E
ester.zhou 已提交
1245 1246 1247 1248 1249 1250 1251

**Error codes**

For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
E
ester.zhou 已提交
1252
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
1253 1254 1255 1256 1257 1258

**Example**

```js
try {
    inputMethodSetting.showOptionalInputMethods((err, data) => {
E
ester.zhou 已提交
1259 1260
        if (err !== undefined) {
            console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
E
ester.zhou 已提交
1261 1262
            return;
        }
E
ester.zhou 已提交
1263
        console.info('Succeeded in showing optionalInputMethods.');
E
ester.zhou 已提交
1264 1265
    });
} catch (err) {
E
ester.zhou 已提交
1266
    console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
E
ester.zhou 已提交
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289
}
```

### showOptionalInputMethods<sup>9+</sup>

showOptionalInputMethods(): Promise&lt;boolean&gt;

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&lt;boolean&gt; | 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                            |
| -------- | -------------------------------------- |
E
ester.zhou 已提交
1290
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
1291 1292 1293 1294 1295

**Example**

```js
inputMethodSetting.showOptionalInputMethods().then((data) => {
E
ester.zhou 已提交
1296
    console.info('Succeeded in showing optionalInputMethods.');
E
ester.zhou 已提交
1297
}).catch((err) => {
E
ester.zhou 已提交
1298
    console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
E
ester.zhou 已提交
1299 1300
})
```
E
ester.zhou 已提交
1301

E
ester.zhou 已提交
1302
### listInputMethod<sup>(deprecated)</sup>
E
ester.zhou 已提交
1303 1304 1305

listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void

E
ester.zhou 已提交
1306 1307 1308 1309 1310
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).
E
ester.zhou 已提交
1311

1312
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
1313

E
ester.zhou 已提交
1314
**Parameters**
E
ester.zhou 已提交
1315

E
ester.zhou 已提交
1316 1317
| Name  | Type                                              | Mandatory| Description                  |
| -------- | -------------------------------------------------- | ---- | ---------------------- |
E
ester.zhou 已提交
1318
| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; | Yes  | Callback used to return the list of installed input methods.|
E
ester.zhou 已提交
1319 1320 1321

**Example**

E
ester.zhou 已提交
1322
```js
E
ester.zhou 已提交
1323
inputMethodSetting.listInputMethod((err,data) => {
E
ester.zhou 已提交
1324 1325
    if (err !== undefined) {
        console.error('Failed to listInputMethod: ' + JSON.stringify(err));
E
ester.zhou 已提交
1326
        return;
E
ester.zhou 已提交
1327
    }
E
ester.zhou 已提交
1328
    console.log('Succeeded in listing inputMethod.');
E
ester.zhou 已提交
1329
 });
E
ester.zhou 已提交
1330
```
E
ester.zhou 已提交
1331

E
ester.zhou 已提交
1332
### listInputMethod<sup>(deprecated)</sup>
E
ester.zhou 已提交
1333

E
ester.zhou 已提交
1334
listInputMethod(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
E
ester.zhou 已提交
1335

E
ester.zhou 已提交
1336 1337 1338 1339 1340
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).
E
ester.zhou 已提交
1341

1342
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
1343

E
ester.zhou 已提交
1344
**Return value**
E
ester.zhou 已提交
1345

E
ester.zhou 已提交
1346 1347
| Type                                                       | Description                  |
| ----------------------------------------------------------- | ---------------------- |
E
ester.zhou 已提交
1348
| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return the list of installed input methods.|
E
ester.zhou 已提交
1349 1350 1351 1352

**Example**

```js
E
ester.zhou 已提交
1353
inputMethodSetting.listInputMethod().then((data) => {
E
ester.zhou 已提交
1354
    console.info('Succeeded in listing inputMethod.');
E
ester.zhou 已提交
1355
}).catch((err) => {
E
ester.zhou 已提交
1356
    console.error('Failed to listInputMethod: ' + JSON.stringify(err));
E
ester.zhou 已提交
1357
})
E
ester.zhou 已提交
1358
```
E
ester.zhou 已提交
1359

E
ester.zhou 已提交
1360
### displayOptionalInputMethod<sup>(deprecated)</sup>
E
ester.zhou 已提交
1361 1362 1363

displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void

E
ester.zhou 已提交
1364 1365 1366 1367 1368
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).
E
ester.zhou 已提交
1369

1370
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
1371

1372
**Parameters**
E
ester.zhou 已提交
1373 1374 1375

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1376
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
E
ester.zhou 已提交
1377

E
ester.zhou 已提交
1378
**Example**
1379

E
ester.zhou 已提交
1380
```js
E
ester.zhou 已提交
1381
inputMethodSetting.displayOptionalInputMethod((err) => {
E
ester.zhou 已提交
1382 1383
    if (err !== undefined) {
        console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
E
ester.zhou 已提交
1384 1385
        return;
    }
E
ester.zhou 已提交
1386
    console.info('Succeeded in displaying optionalInputMethod.');
E
ester.zhou 已提交
1387
});
E
ester.zhou 已提交
1388
```
E
ester.zhou 已提交
1389

E
ester.zhou 已提交
1390 1391 1392
### displayOptionalInputMethod<sup>(deprecated)</sup>

displayOptionalInputMethod(): Promise&lt;void&gt;
E
ester.zhou 已提交
1393

E
ester.zhou 已提交
1394
Displays a dialog box for selecting an input method. This API uses a promise to return the result.
E
ester.zhou 已提交
1395

E
ester.zhou 已提交
1396 1397 1398
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [showOptionalInputMethods()](#showoptionalinputmethods9-1).
E
ester.zhou 已提交
1399

E
ester.zhou 已提交
1400
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
1401

E
ester.zhou 已提交
1402
**Return value**
E
ester.zhou 已提交
1403 1404 1405

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
1406
| Promise&lt;void&gt; | Promise that returns no value.|
E
ester.zhou 已提交
1407

E
ester.zhou 已提交
1408 1409 1410
**Example**

```js
E
ester.zhou 已提交
1411
inputMethodSetting.displayOptionalInputMethod().then(() => {
E
ester.zhou 已提交
1412
    console.info('Succeeded in displaying optionalInputMethod.');
E
ester.zhou 已提交
1413
}).catch((err) => {
E
ester.zhou 已提交
1414
    console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
E
ester.zhou 已提交
1415
})
1416
```