js-apis-inputmethod.md 47.3 KB
Newer Older
E
ester.zhou 已提交
1 2
# Input Method Framework

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 12


## Modules to Import

```
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.|
| id<sup>9+</sup>    | string | Yes| No| Unique ID of the input method.|
| label<sup>9+</sup>    | string | Yes| No| External display name of the input method.|
| icon<sup>9+</sup>    | string | Yes| No| Icon of the input method.|
| iconId<sup>9+</sup>    | number | Yes| No| Icon ID of the input method.|
| extra<sup>9+</sup>    | object | Yes| No| Extra information about the input method.|
| packageName<sup>(deprecated)</sup> | string | Yes| No| Name of the input method package.<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.<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 105
Switches to another input method. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
106 107 108 109 110 111 112

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

**Parameters**

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

**Error codes**
117

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

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
| 12800008 | Input method settings extension error. |
124 125 126 127

**Example**

```js
E
ester.zhou 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
try{
    inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}, (err, result) => {
        if (err) {
            console.error('switchInputMethod err: ' + JSON.stringify(err));
            return;
        }
        if (result) {
            console.info('Success to switchInputMethod.(callback)');
        } else {
            console.error('Failed to switchInputMethod.(callback)');
        }
    });
} catch(err) {
    console.error('switchInputMethod err: ' + JSON.stringify(err));
}
143 144
```
## inputMethod.switchInputMethod<sup>9+</sup>
E
ester.zhou 已提交
145
switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt;
146

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

**Required permissions**: ohos.permission.CONNECT_IME_ABILITY
E
ester.zhou 已提交
150

151 152 153 154 155 156
**System capability**: SystemCapability.MiscServices.InputMethodFramework

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
157
|target |  [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.|
158 159

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

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

E
ester.zhou 已提交
165
**Error codes**
166

E
ester.zhou 已提交
167 168 169 170 171 172 173 174
For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
| 12800008 | Input method settings extension error. |

**Example**
175 176

```js
E
ester.zhou 已提交
177 178 179 180 181 182 183 184 185 186 187 188 189
try {
    inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}).then((result) => {
        if (result) {
            console.info('Success to switchInputMethod.');
        } else {
            console.error('Failed to switchInputMethod.');
        }
    }).catch((err) => {
        console.error('switchInputMethod err: ' + JSON.stringify(err));
    })
} catch(err) {
    console.error('switchInputMethod err: ' + JSON.stringify(err));
}
E
ester.zhou 已提交
190
```
E
ester.zhou 已提交
191

E
ester.zhou 已提交
192 193 194 195 196 197 198 199 200 201 202 203
## 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 已提交
204
| [InputMethodProperty](#inputmethodproperty8) | **InputmethodProperty** instance of the current input method.|
E
ester.zhou 已提交
205 206 207

**Example**

E
ester.zhou 已提交
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
```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.

**Required permissions**: ohos.permission.CONNECT_IME_ABILITY

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| target |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.|
| callback | AsyncCallback&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. |

**Error codes**

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

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
| 12800008 | Input method settings extension error. |

**Example**
E
ester.zhou 已提交
239 240

```js
E
ester.zhou 已提交
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 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 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 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
let inputMethodSubtype = {
    id: "com.example.kikakeyboard",
    label: "ServiceExtAbility",
    name: "",
    mode: "upper",
    locale: "",
    language: "",
    icon: "",
    iconId: 0,
    extra: {}
}
try {
    inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype, (err, result) => {
        if (err) {
            console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err));
            return;
        }
        if (result) {
            console.info('Success to switchCurrentInputMethodSubtype.(callback)');
        } else {
            console.error('Failed to switchCurrentInputMethodSubtype.(callback)');
        }
    });
} catch(err) {
    console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err));
}
```

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

**Required permissions**: ohos.permission.CONNECT_IME_ABILITY

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
|target |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.|

**Return value**

| Type                                     | Description                        |
| ----------------------------------------- | ---------------------------- |
| Promise\<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.        |
| 12800008 | Input method settings extension error. |

**Example**

```js
let inputMethodSubtype = {
    id: "com.example.kikakeyboard",
    label: "ServiceExtAbility",
    name: "",
    mode: "upper",
    locale: "",
    language: "",
    icon: "",
    iconId: 0,
    extra: {}
}
try {
    inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype).then((result) => {
        if (result) {
            console.info('Success to switchCurrentInputMethodSubtype.');
        } else {
            console.error('Failed to switchCurrentInputMethodSubtype.');
        }
    }).catch((err) => {
        console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err));
    })
} catch(err) {
    console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err));
}
```

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

**Required permissions**: ohos.permission.CONNECT_IME_ABILITY

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
|inputMethodProperty |  [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.|
|inputMethodSubtype |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.|
| callback | AsyncCallback&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. |

**Error codes**

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

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800005 | Configuration persisting error.        |
| 12800008 | Input method settings extension error. |

**Example**

```js
let inputMethodProperty = {
    packageName: "com.example.kikakeyboard",
    methodId: "ServiceExtAbility",
    extra: {}
}
let inputMethodSubProperty = {
    id: "com.example.kikakeyboard",
    label: "ServiceExtAbility",
    name: "",
    mode: "upper",
    locale: "",
    language: "",
    icon: "",
    iconId: 0,
    extra: {}
}
try {
    inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty, (err,result) => {
        if (err) {
            console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err));
            return;
        }
        if (result) {
            console.info('Success to switchCurrentInputMethodAndSubtype.(callback)');
        } else {
            console.error('Failed to switchCurrentInputMethodAndSubtype.(callback)');
        }
    });
} catch (err) {
    console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err));
}
```

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

**Required permissions**: ohos.permission.CONNECT_IME_ABILITY

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
|inputMethodProperty |  [InputMethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.|
|inputMethodSubtype |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Input method subtype to switch to.|

**Return value**

| Type                                     | Description                        |
| ----------------------------------------- | ---------------------------- |
| Promise\<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.        |
| 12800008 | Input method settings extension error. |

**Example**

```js
let inputMethodProperty = {
    packageName: "com.example.kikakeyboard",
    methodId: "ServiceExtAbility",
    extra: {}
}
let inputMethodSubProperty = {
    id: "com.example.kikakeyboard",
    label: "ServiceExtAbility",
    name: "",
    mode: "upper",
    locale: "",
    language: "",
    icon: "",
    iconId: 0,
    extra: {}
}
try {
    inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty).then((result) => {
        if (result) {
            console.info('Success to switchCurrentInputMethodAndSubtype.');
        } else {
            console.error('Failed to switchCurrentInputMethodAndSubtype.');
        }
    }).catch((err) => {
        console.error('switchCurrentInputMethodAndSubtype err: ' + err);
    })
} catch(err) {
    console.error('switchCurrentInputMethodAndSubtype err: ' + err);
}
```

## inputMethod.getInputMethodController<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();
524
```
E
ester.zhou 已提交
525

E
ester.zhou 已提交
526
## InputMethodController
E
ester.zhou 已提交
527

E
ester.zhou 已提交
528
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 已提交
529

E
ester.zhou 已提交
530
### stopInputSession<sup>9+</sup>
E
ester.zhou 已提交
531

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

E
ester.zhou 已提交
534
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 已提交
535

536
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
537

E
ester.zhou 已提交
538
**Parameters**
E
ester.zhou 已提交
539

E
ester.zhou 已提交
540 541
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
542 543 544 545 546 547 548 549 550 551
| 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. |

**Error codes**

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

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method settings extension error. |
E
ester.zhou 已提交
552

E
ester.zhou 已提交
553
**Example**
E
ester.zhou 已提交
554

E
ester.zhou 已提交
555
```js
E
ester.zhou 已提交
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
try {
    inputMethodController.stopInputSession((error, result) => {
        if (error) {
            console.error('stopInputSession err: ' + JSON.stringify(error));
            return;
        }
        if (result) {
            console.info('Success to stopInputSession.(callback)');
        } else {
            console.error('Failed to stopInputSession.(callback)');
        }
    });
} catch(error) {
    console.error('stopInputSession err: ' + JSON.stringify(error));
}
E
ester.zhou 已提交
571 572
```

E
ester.zhou 已提交
573
### stopInputSession<sup>9+</sup>
E
ester.zhou 已提交
574

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

E
ester.zhou 已提交
577
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 已提交
578

579
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
580

E
ester.zhou 已提交
581
**Return value**
E
ester.zhou 已提交
582

E
ester.zhou 已提交
583 584
| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
585
| 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 已提交
586

E
ester.zhou 已提交
587 588 589
**Error codes**

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

E
ester.zhou 已提交
591 592 593 594 595 596
| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method settings extension error. |

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

E
ester.zhou 已提交
598
```js
E
ester.zhou 已提交
599 600 601 602 603 604 605 606 607 608 609 610 611
try {
    inputMethodController.stopInputSession().then((result) => {
        if (result) {
            console.info('Success to stopInputSession.');
        } else {
            console.error('Failed to stopInputSession.');
        }
    }).catch((err) => {
        console.error('stopInputSession err: ' + JSON.stringify(err));
    })
} catch(err) {
    console.error('stopInputSession err: ' + JSON.stringify(err));
}
E
ester.zhou 已提交
612 613
```

E
ester.zhou 已提交
614
### showSoftKeyboard<sup>9+</sup>
E
ester.zhou 已提交
615 616 617

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

E
ester.zhou 已提交
618 619 620
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
E
ester.zhou 已提交
621 622 623 624 625 626 627

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

**Parameters**

| Name  | Type                 | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
E
ester.zhou 已提交
628 629 630 631 632 633 634 635 636 637
| 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. |

**Error codes**

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

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method settings extension error. |
E
ester.zhou 已提交
638 639 640 641

**Example**

```js
E
ester.zhou 已提交
642
inputMethodController.showSoftKeyboard((err) => {
E
ester.zhou 已提交
643
    if (err === undefined) {
E
ester.zhou 已提交
644 645 646 647 648 649 650
        console.info('showSoftKeyboard success');
    } else {
        console.error('showSoftKeyboard failed because : ' + JSON.stringify(err));
    }
})
```

E
ester.zhou 已提交
651
### showSoftKeyboard<sup>9+</sup>
E
ester.zhou 已提交
652 653 654

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

E
ester.zhou 已提交
655 656 657
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
E
ester.zhou 已提交
658 659 660 661 662 663 664 665 666

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

**Return value**

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

E
ester.zhou 已提交
667 668 669 670 671 672 673 674 675
**Error codes**

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

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method settings extension error. |

E
ester.zhou 已提交
676 677 678
**Example**

```js
E
ester.zhou 已提交
679
inputMethodController.showSoftKeyboard().then(async (err) => {
E
ester.zhou 已提交
680 681
    console.log('showSoftKeyboard success');
}).catch((err) => {
E
ester.zhou 已提交
682
    console.error('showSoftKeyboard err: ' + JSON.stringify(err));
E
ester.zhou 已提交
683 684 685
});
```

E
ester.zhou 已提交
686
### hideSoftKeyboard<sup>9+</sup>
E
ester.zhou 已提交
687 688 689

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

E
ester.zhou 已提交
690 691 692
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
E
ester.zhou 已提交
693 694 695 696 697 698 699

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

**Parameters**

| Name  | Type                 | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
E
ester.zhou 已提交
700 701 702 703 704 705 706 707 708 709
| 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. |

**Error codes**

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

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method settings extension error. |
E
ester.zhou 已提交
710 711 712 713

**Example**

```js
E
ester.zhou 已提交
714
inputMethodController.hideSoftKeyboard((err) => {
E
ester.zhou 已提交
715
    if (err === undefined) {
E
ester.zhou 已提交
716 717 718 719 720 721 722
        console.info('hideSoftKeyboard success');
    } else {
        console.error('hideSoftKeyboard failed because : ' + JSON.stringify(err));
    }
})
```

E
ester.zhou 已提交
723
### hideSoftKeyboard<sup>9+</sup>
E
ester.zhou 已提交
724 725 726

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

E
ester.zhou 已提交
727 728 729
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
E
ester.zhou 已提交
730 731 732 733 734 735 736 737 738

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

**Return value**

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

E
ester.zhou 已提交
739 740 741 742 743 744 745 746 747
**Error codes**

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

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800003 | Input method client error.             |
| 12800008 | Input method settings extension error. |

E
ester.zhou 已提交
748 749 750
**Example**

```js
E
ester.zhou 已提交
751
inputMethodController.hideSoftKeyboard().then(async (err) => {
E
ester.zhou 已提交
752 753
    console.log('hideSoftKeyboard success');
}).catch((err) => {
E
ester.zhou 已提交
754
    console.error('hideSoftKeyboard err: ' + JSON.stringify(err));
E
ester.zhou 已提交
755
});
E
ester.zhou 已提交
756 757
```

E
ester.zhou 已提交
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
### 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|
| -------- | -------- | -------- | -------- |
| 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. |

**Example**

```js
inputMethodController.stopInput((error, result) => {
    if (error) {
        console.error('failed to stopInput because: ' + JSON.stringify(error));
        return;
    }
    if (result) {
        console.info('Success to stopInput.(callback)');
    } else {
        console.error('Failed to stopInput.(callback)');
    }
});
```

### stopInput<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) {
        console.info('Success to stopInput.');
    } else {
        console.error('Failed to stopInput.');
    }
}).catch((err) => {
    console.error('stopInput err: ' + err);
})
```

E
ester.zhou 已提交
824
## InputMethodSetting<sup>8+</sup>
E
ester.zhou 已提交
825

E
ester.zhou 已提交
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 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 887 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 928 929 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 998 999 1000 1001 1002
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.                 |
| 12800008 | Input method settings extension error. |

**Example**

```js
let inputMethodProperty = {
    packageName:'com.example.kikakeyboard',
    methodId:'com.example.kikakeyboard',
    extra:{}
}
try {
    inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => {
        if (err) {
            console.error('listInputMethodSubtype failed: ' + JSON.stringify(err));
            return;
        }
        console.log('listInputMethodSubtype success');
    });
} catch (err) {
    console.error('listInputMethodSubtype failed: ' + JSON.stringify(err));
}
```

### 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.                 |
| 12800008 | Input method settings extension error. |

**Example**

```js
let inputMethodProperty = {
    packageName:'com.example.kikakeyboard',
    methodId:'com.example.kikakeyboard',
    extra:{}
}
try {
    inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => {
        console.info('listInputMethodSubtype success');
    }).catch((err) => {
        console.error('listInputMethodSubtype err: ' + JSON.stringify(err));
    })
} catch(err) {
    console.error('listInputMethodSubtype err: ' + JSON.stringify(err));
}
```

### 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.                 |
| 12800008 | Input method settings extension error. |

**Example**

```js
try {
    inputMethodSetting.listCurrentInputMethodSubtype((err, data) => {
        if (err) {
            console.error('listCurrentInputMethodSubtype failed: ' + JSON.stringify(err));
            return;
        }
        console.log('listCurrentInputMethodSubtype success');
    });
} catch(err) {
    console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err));
}
```
E
ester.zhou 已提交
1003

E
ester.zhou 已提交
1004
### listCurrentInputMethodSubtype<sup>9+</sup>
E
ester.zhou 已提交
1005

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

E
ester.zhou 已提交
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 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
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.                 |
| 12800008 | Input method settings extension error. |

**Example**

```js
try {
    inputMethodSetting.listCurrentInputMethodSubtype().then((data) => {
        console.info('listCurrentInputMethodSubtype success');
    }).catch((err) => {
        console.error('listCurrentInputMethodSubtype err: ' + err);
    })
} catch(err) {
    console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err));
}
```

### 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 已提交
1046 1047 1048 1049 1050 1051 1052 1053

**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 已提交
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
| 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.                 |
| 12800008 | Input method settings extension error. |
E
ester.zhou 已提交
1064 1065 1066 1067

**Example**

```js
E
ester.zhou 已提交
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
try {
    inputMethodSetting.getInputMethods(true, (err,data) => {
        if (err) {
            console.error('getInputMethods failed: ' + JSON.stringify(err));
            return;
        }
        console.log('getInputMethods success');
    });
} catch (err) {
    console.error('getInputMethods failed: ' + JSON.stringify(err));
}
E
ester.zhou 已提交
1079 1080
```

E
ester.zhou 已提交
1081
### getInputMethods<sup>9+</sup>
E
ester.zhou 已提交
1082

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

E
ester.zhou 已提交
1085
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 已提交
1086 1087 1088 1089 1090 1091 1092 1093 1094

**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 已提交
1095 1096 1097 1098 1099 1100 1101 1102 1103
**Error codes**

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

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800001 | Package manager error.                 |
| 12800008 | Input method settings extension error. |

E
ester.zhou 已提交
1104 1105 1106 1107
**Return value**

| Type                                                        | Description                         |
| ------------------------------------------------------------ | ----------------------------- |
E
ester.zhou 已提交
1108
| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return a list of activated or deactivated input methods.|
E
ester.zhou 已提交
1109 1110 1111 1112

**Example**

```js
E
ester.zhou 已提交
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
try {
    inputMethodSetting.getInputMethods(true).then((data) => {
        console.info('getInputMethods success');
    }).catch((err) => {
        console.error('getInputMethods err: ' + JSON.stringify(err));
    })
} catch(err) {
    console.error('getInputMethods err: ' + JSON.stringify(err));
}
```

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

**Required permissions**: ohos.permission.CONNECT_IME_ABILITY

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

**Parameters**

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

**Error codes**

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

| Error Code ID| Error Message                            |
| -------- | -------------------------------------- |
| 12800008 | Input method settings extension error. |

**Example**

```js
try {
    inputMethodSetting.showOptionalInputMethods((err, data) => {
        if (err) {
            console.error('showOptionalInputMethods failed: ' + JSON.stringify(err));
            return;
        }
        console.info('showOptionalInputMethods success');
    });
} catch (err) {
    console.error('showOptionalInputMethods failed: ' + JSON.stringify(err));
}
```

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

**Required permissions**: ohos.permission.CONNECT_IME_ABILITY

**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                            |
| -------- | -------------------------------------- |
| 12800008 | Input method settings extension error. |

**Example**

```js
inputMethodSetting.showOptionalInputMethods().then((data) => {
    console.info('displayOptionalInputMethod success.');
E
ester.zhou 已提交
1193
}).catch((err) => {
E
ester.zhou 已提交
1194
    console.error('displayOptionalInputMethod err: ' + err);
E
ester.zhou 已提交
1195 1196
})
```
E
ester.zhou 已提交
1197

E
ester.zhou 已提交
1198
### listInputMethod<sup>(deprecated)</sup>
E
ester.zhou 已提交
1199 1200 1201

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

E
ester.zhou 已提交
1202 1203 1204 1205 1206
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 已提交
1207

1208
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
1209

E
ester.zhou 已提交
1210
**Parameters**
E
ester.zhou 已提交
1211

E
ester.zhou 已提交
1212 1213
| Name  | Type                                              | Mandatory| Description                  |
| -------- | -------------------------------------------------- | ---- | ---------------------- |
E
ester.zhou 已提交
1214
| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; | Yes  | Callback used to return the list of installed input methods.|
E
ester.zhou 已提交
1215 1216 1217

**Example**

E
ester.zhou 已提交
1218
```js
E
ester.zhou 已提交
1219
inputMethodSetting.listInputMethod((err,data) => {
E
ester.zhou 已提交
1220
    if (err) {
E
ester.zhou 已提交
1221
        console.error('listInputMethod failed because: ' + JSON.stringify(err));
E
ester.zhou 已提交
1222
        return;
E
ester.zhou 已提交
1223
    }
E
ester.zhou 已提交
1224
    console.log('listInputMethod success');
E
ester.zhou 已提交
1225
 });
E
ester.zhou 已提交
1226
```
E
ester.zhou 已提交
1227

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

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

E
ester.zhou 已提交
1232 1233 1234 1235 1236
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 已提交
1237

1238
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
1239

E
ester.zhou 已提交
1240
**Return value**
E
ester.zhou 已提交
1241

E
ester.zhou 已提交
1242 1243
| Type                                                       | Description                  |
| ----------------------------------------------------------- | ---------------------- |
E
ester.zhou 已提交
1244
| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return the list of installed input methods.|
E
ester.zhou 已提交
1245 1246 1247 1248

**Example**

```js
E
ester.zhou 已提交
1249
inputMethodSetting.listInputMethod().then((data) => {
E
ester.zhou 已提交
1250
    console.info('listInputMethod success');
E
ester.zhou 已提交
1251
}).catch((err) => {
E
ester.zhou 已提交
1252
    console.error('listInputMethod err: ' + JSON.stringify(err));
E
ester.zhou 已提交
1253
})
E
ester.zhou 已提交
1254
```
E
ester.zhou 已提交
1255

E
ester.zhou 已提交
1256
### displayOptionalInputMethod<sup>(deprecated)</sup>
E
ester.zhou 已提交
1257 1258 1259

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

E
ester.zhou 已提交
1260 1261 1262 1263 1264
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 已提交
1265

1266
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
1267

1268
**Parameters**
E
ester.zhou 已提交
1269 1270 1271

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1272
| 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 已提交
1273

E
ester.zhou 已提交
1274
**Example**
1275

E
ester.zhou 已提交
1276
```js
E
ester.zhou 已提交
1277
inputMethodSetting.displayOptionalInputMethod((err) => {
E
ester.zhou 已提交
1278
    if (err) {
E
ester.zhou 已提交
1279
        console.error('displayOptionalInputMethod failed because: ' + JSON.stringify(err));
E
ester.zhou 已提交
1280 1281
        return;
    }
E
ester.zhou 已提交
1282
    console.info('displayOptionalInputMethod success');
E
ester.zhou 已提交
1283
});
E
ester.zhou 已提交
1284
```
E
ester.zhou 已提交
1285

E
ester.zhou 已提交
1286 1287 1288
### displayOptionalInputMethod<sup>(deprecated)</sup>

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

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

E
ester.zhou 已提交
1292 1293 1294
> **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 已提交
1295

E
ester.zhou 已提交
1296
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
1297

E
ester.zhou 已提交
1298
**Return value**
E
ester.zhou 已提交
1299 1300 1301

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

E
ester.zhou 已提交
1304 1305 1306
**Example**

```js
E
ester.zhou 已提交
1307 1308
inputMethodSetting.displayOptionalInputMethod().then(() => {
    console.info('displayOptionalInputMethod success');
E
ester.zhou 已提交
1309
}).catch((err) => {
E
ester.zhou 已提交
1310
    console.error('displayOptionalInputMethod err: ' + err);
E
ester.zhou 已提交
1311
})
1312
```