js-apis-inputmethod.md 48.7 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
## InputMethodSetting<sup>8+</sup>
E
ester.zhou 已提交
843

E
ester.zhou 已提交
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
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 已提交
912
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
913 914 915 916 917

**Example**

```js
let inputMethodProperty = {
E
ester.zhou 已提交
918 919 920 921
    packageName: 'com.example.kikakeyboard',
    methodId: 'com.example.kikakeyboard',
    name: 'com.example.kikakeyboard',
    id: 'com.example.kikakeyboard',
E
ester.zhou 已提交
922 923 924 925
    extra:{}
}
try {
    inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => {
E
ester.zhou 已提交
926 927
        if (err !== undefined) {
            console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
928 929
            return;
        }
E
ester.zhou 已提交
930
        console.log('Succeeded in listing inputMethodSubtype.');
E
ester.zhou 已提交
931 932
    });
} catch (err) {
E
ester.zhou 已提交
933
    console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
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
}
```

### 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 已提交
964
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
965 966 967 968 969

**Example**

```js
let inputMethodProperty = {
E
ester.zhou 已提交
970 971 972 973
    packageName: 'com.example.kikakeyboard',
    methodId: 'com.example.kikakeyboard',
    name: 'com.example.kikakeyboard',
    id: 'com.example.kikakeyboard',
E
ester.zhou 已提交
974 975 976 977
    extra:{}
}
try {
    inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => {
E
ester.zhou 已提交
978
        console.info('Succeeded in listing inputMethodSubtype.');
E
ester.zhou 已提交
979
    }).catch((err) => {
E
ester.zhou 已提交
980
        console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
981 982
    })
} catch(err) {
E
ester.zhou 已提交
983
    console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
}
```

### 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 已提交
1008
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
1009 1010 1011 1012 1013 1014

**Example**

```js
try {
    inputMethodSetting.listCurrentInputMethodSubtype((err, data) => {
E
ester.zhou 已提交
1015 1016
        if (err !== undefined) {
            console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
1017 1018
            return;
        }
E
ester.zhou 已提交
1019
        console.log('Succeeded in listing currentInputMethodSubtype.');
E
ester.zhou 已提交
1020 1021
    });
} catch(err) {
E
ester.zhou 已提交
1022
    console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
1023 1024
}
```
E
ester.zhou 已提交
1025

E
ester.zhou 已提交
1026
### listCurrentInputMethodSubtype<sup>9+</sup>
E
ester.zhou 已提交
1027

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

E
ester.zhou 已提交
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
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 已提交
1047
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
1048 1049 1050 1051 1052 1053

**Example**

```js
try {
    inputMethodSetting.listCurrentInputMethodSubtype().then((data) => {
E
ester.zhou 已提交
1054
        console.info('Succeeded in listing currentInputMethodSubtype.');
E
ester.zhou 已提交
1055
    }).catch((err) => {
E
ester.zhou 已提交
1056
        console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
1057 1058
    })
} catch(err) {
E
ester.zhou 已提交
1059
    console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err));
E
ester.zhou 已提交
1060 1061 1062 1063 1064 1065 1066 1067
}
```

### 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 已提交
1068 1069 1070 1071 1072 1073 1074 1075

**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 已提交
1076 1077 1078 1079 1080 1081 1082 1083 1084
| 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 已提交
1085
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
1086 1087 1088 1089

**Example**

```js
E
ester.zhou 已提交
1090 1091
try {
    inputMethodSetting.getInputMethods(true, (err,data) => {
E
ester.zhou 已提交
1092 1093
        if (err !== undefined) {
            console.error('Failed to getInputMethods: ' + JSON.stringify(err));
E
ester.zhou 已提交
1094 1095
            return;
        }
E
ester.zhou 已提交
1096
        console.log('Succeeded in getting inputMethods.');
E
ester.zhou 已提交
1097 1098
    });
} catch (err) {
E
ester.zhou 已提交
1099
    console.error('Failed to getInputMethods: ' + JSON.stringify(err));
E
ester.zhou 已提交
1100
}
E
ester.zhou 已提交
1101 1102
```

E
ester.zhou 已提交
1103
### getInputMethods<sup>9+</sup>
E
ester.zhou 已提交
1104

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

E
ester.zhou 已提交
1107
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 已提交
1108 1109 1110 1111 1112 1113 1114 1115 1116

**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 已提交
1117 1118 1119 1120 1121 1122 1123
**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 已提交
1124
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
1125

E
ester.zhou 已提交
1126 1127 1128 1129
**Return value**

| Type                                                        | Description                         |
| ------------------------------------------------------------ | ----------------------------- |
E
ester.zhou 已提交
1130
| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return a list of activated or deactivated input methods.|
E
ester.zhou 已提交
1131 1132 1133 1134

**Example**

```js
E
ester.zhou 已提交
1135 1136
try {
    inputMethodSetting.getInputMethods(true).then((data) => {
E
ester.zhou 已提交
1137
        console.info('Succeeded in getting inputMethods.');
E
ester.zhou 已提交
1138
    }).catch((err) => {
E
ester.zhou 已提交
1139
        console.error('Failed to getInputMethods: ' + JSON.stringify(err));
E
ester.zhou 已提交
1140 1141
    })
} catch(err) {
E
ester.zhou 已提交
1142
    console.error('Failed to getInputMethods: ' + JSON.stringify(err));
E
ester.zhou 已提交
1143 1144 1145 1146 1147 1148 1149 1150 1151
}
```

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

E
ester.zhou 已提交
1152
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
E
ester.zhou 已提交
1153 1154 1155 1156 1157 1158 1159

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1160
| 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 已提交
1161 1162 1163 1164 1165 1166 1167

**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 已提交
1168
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
1169 1170 1171 1172 1173 1174

**Example**

```js
try {
    inputMethodSetting.showOptionalInputMethods((err, data) => {
E
ester.zhou 已提交
1175 1176
        if (err !== undefined) {
            console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
E
ester.zhou 已提交
1177 1178
            return;
        }
E
ester.zhou 已提交
1179
        console.info('Succeeded in showing optionalInputMethods.');
E
ester.zhou 已提交
1180 1181
    });
} catch (err) {
E
ester.zhou 已提交
1182
    console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
E
ester.zhou 已提交
1183 1184 1185 1186 1187 1188 1189 1190 1191
}
```

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

E
ester.zhou 已提交
1192
**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications)
E
ester.zhou 已提交
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207

**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 已提交
1208
| 12800008 | Input method manager service error. |
E
ester.zhou 已提交
1209 1210 1211 1212 1213

**Example**

```js
inputMethodSetting.showOptionalInputMethods().then((data) => {
E
ester.zhou 已提交
1214
    console.info('Succeeded in showing optionalInputMethods.');
E
ester.zhou 已提交
1215
}).catch((err) => {
E
ester.zhou 已提交
1216
    console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
E
ester.zhou 已提交
1217 1218
})
```
E
ester.zhou 已提交
1219

E
ester.zhou 已提交
1220
### listInputMethod<sup>(deprecated)</sup>
E
ester.zhou 已提交
1221 1222 1223

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

E
ester.zhou 已提交
1224 1225 1226 1227 1228
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 已提交
1229

1230
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
1231

E
ester.zhou 已提交
1232
**Parameters**
E
ester.zhou 已提交
1233

E
ester.zhou 已提交
1234 1235
| Name  | Type                                              | Mandatory| Description                  |
| -------- | -------------------------------------------------- | ---- | ---------------------- |
E
ester.zhou 已提交
1236
| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; | Yes  | Callback used to return the list of installed input methods.|
E
ester.zhou 已提交
1237 1238 1239

**Example**

E
ester.zhou 已提交
1240
```js
E
ester.zhou 已提交
1241
inputMethodSetting.listInputMethod((err,data) => {
E
ester.zhou 已提交
1242 1243
    if (err !== undefined) {
        console.error('Failed to listInputMethod: ' + JSON.stringify(err));
E
ester.zhou 已提交
1244
        return;
E
ester.zhou 已提交
1245
    }
E
ester.zhou 已提交
1246
    console.log('Succeeded in listing inputMethod.');
E
ester.zhou 已提交
1247
 });
E
ester.zhou 已提交
1248
```
E
ester.zhou 已提交
1249

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

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

E
ester.zhou 已提交
1254 1255 1256 1257 1258
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 已提交
1259

1260
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
1261

E
ester.zhou 已提交
1262
**Return value**
E
ester.zhou 已提交
1263

E
ester.zhou 已提交
1264 1265
| Type                                                       | Description                  |
| ----------------------------------------------------------- | ---------------------- |
E
ester.zhou 已提交
1266
| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return the list of installed input methods.|
E
ester.zhou 已提交
1267 1268 1269 1270

**Example**

```js
E
ester.zhou 已提交
1271
inputMethodSetting.listInputMethod().then((data) => {
E
ester.zhou 已提交
1272
    console.info('Succeeded in listing inputMethod.');
E
ester.zhou 已提交
1273
}).catch((err) => {
E
ester.zhou 已提交
1274
    console.error('Failed to listInputMethod: ' + JSON.stringify(err));
E
ester.zhou 已提交
1275
})
E
ester.zhou 已提交
1276
```
E
ester.zhou 已提交
1277

E
ester.zhou 已提交
1278
### displayOptionalInputMethod<sup>(deprecated)</sup>
E
ester.zhou 已提交
1279 1280 1281

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

E
ester.zhou 已提交
1282 1283 1284 1285 1286
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 已提交
1287

1288
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
1289

1290
**Parameters**
E
ester.zhou 已提交
1291 1292 1293

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

E
ester.zhou 已提交
1296
**Example**
1297

E
ester.zhou 已提交
1298
```js
E
ester.zhou 已提交
1299
inputMethodSetting.displayOptionalInputMethod((err) => {
E
ester.zhou 已提交
1300 1301
    if (err !== undefined) {
        console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
E
ester.zhou 已提交
1302 1303
        return;
    }
E
ester.zhou 已提交
1304
    console.info('Succeeded in displaying optionalInputMethod.');
E
ester.zhou 已提交
1305
});
E
ester.zhou 已提交
1306
```
E
ester.zhou 已提交
1307

E
ester.zhou 已提交
1308 1309 1310
### displayOptionalInputMethod<sup>(deprecated)</sup>

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

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

E
ester.zhou 已提交
1314 1315 1316
> **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 已提交
1317

E
ester.zhou 已提交
1318
**System capability**: SystemCapability.MiscServices.InputMethodFramework
E
ester.zhou 已提交
1319

E
ester.zhou 已提交
1320
**Return value**
E
ester.zhou 已提交
1321 1322 1323

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

E
ester.zhou 已提交
1326 1327 1328
**Example**

```js
E
ester.zhou 已提交
1329
inputMethodSetting.displayOptionalInputMethod().then(() => {
E
ester.zhou 已提交
1330
    console.info('Succeeded in displaying optionalInputMethod.');
E
ester.zhou 已提交
1331
}).catch((err) => {
E
ester.zhou 已提交
1332
    console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err));
E
ester.zhou 已提交
1333
})
1334
```