1# @ohos.telephony.call (Call) 2 3The **call** module provides call management functions, including making calls, redirecting to the dial screen, obtaining the call status, and formatting phone numbers. 4 5To subscribe to call status changes, use [`observer.on('callStateChange')`](js-apis-observer.md#observeroncallstatechange). 6 7>**NOTE** 8> 9>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. 10 11## Modules to Import 12 13```ts 14import { call } from '@kit.TelephonyKit'; 15``` 16 17 18## call.dial<sup>(deprecated)</sup> 19 20dial\(phoneNumber: string, callback: AsyncCallback\<boolean\>\): void 21 22Initiates a call. This API uses an asynchronous callback to return the result. 23 24> **NOTE** 25> 26> This API is supported since API version 6 and deprecated since API version 9. The substitute API is available only for system applications. 27 28**Required permissions**: ohos.permission.PLACE_CALL (available only for system applications) 29 30**System capability**: SystemCapability.Telephony.CallManager 31 32**Parameters** 33 34| Name | Type | Mandatory| Description | 35| ----------- | ---------------------------- | ---- | --------------------------------------- | 36| phoneNumber | string | Yes | Phone number. | 37| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.| 38 39**Example** 40 41```ts 42import { BusinessError } from '@kit.BasicServicesKit'; 43 44call.dial("138xxxxxxxx", (err: BusinessError, data: boolean) => { 45 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 46}); 47``` 48 49 50## call.dial<sup>(deprecated)</sup> 51 52dial\(phoneNumber: string, options: DialOptions, callback: AsyncCallback\<boolean\>\): void 53 54Initiates a call. You can set call options as needed. This API uses an asynchronous callback to return the result. 55 56> **NOTE** 57> 58> This API is supported since API version 6 and deprecated since API version 9. The substitute API is available only for system applications. 59 60**Required permissions**: ohos.permission.PLACE_CALL (available only for system applications) 61 62**System capability**: SystemCapability.Telephony.CallManager 63 64**Parameters** 65 66| Name | Type | Mandatory| Description | 67| ----------- | ---------------------------- | ---- | --------------------------------------- | 68| phoneNumber | string | Yes | Phone number. | 69| options | [DialOptions](#dialoptions) | Yes | Call option, which indicates whether the call is a voice call or video call. | 70| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.| 71 72**Example** 73 74```ts 75import { BusinessError } from '@kit.BasicServicesKit'; 76 77let dialOptions: call.DialOptions = { 78 extras: false 79} 80call.dial("138xxxxxxxx", dialOptions, (err: BusinessError, data: boolean) => { 81 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 82}); 83``` 84 85## call.dial<sup>(deprecated)</sup> 86 87dial\(phoneNumber: string, options?: DialOptions\): Promise\<boolean\> 88 89Initiates a call. You can set call options as needed. This API uses a promise to return the result. 90 91> **NOTE** 92> 93> This API is supported since API version 6 and deprecated since API version 9. The substitute API is available only for system applications. 94 95**Required permissions**: ohos.permission.PLACE_CALL (available only for system applications) 96 97**System capability**: SystemCapability.Telephony.CallManager 98 99**Parameters** 100 101| Name | Type | Mandatory| Description | 102| ----------- | --------------------------- | ---- | -------------------------------------- | 103| phoneNumber | string | Yes | Phone number. | 104| options | [DialOptions](#dialoptions) | No | Call option, which indicates whether the call is a voice call or video call.| 105 106**Return value** 107 108| Type | Description | 109| ---------------------- | ------------------------------------------------------------ | 110| Promise<boolean> | Promise used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.| 111 112**Example** 113 114```ts 115import { BusinessError } from '@kit.BasicServicesKit'; 116 117let dialOptions: call.DialOptions = { 118 extras: false 119} 120call.dial("138xxxxxxxx", dialOptions).then((data: boolean) => { 121 console.log(`dial success, promise: data->${JSON.stringify(data)}`); 122}).catch((err: BusinessError) => { 123 console.error(`dial fail, promise: err->${JSON.stringify(err)}`); 124}); 125``` 126 127## call.makeCall<sup>7+</sup> 128 129makeCall\(phoneNumber: string, callback: AsyncCallback\<void\>\): void 130 131Launches the call screen and displays the dialed number. This API uses an asynchronous callback to return the result. This API can be called only in a UIAbility. 132 133**Atomic service API**: This API can be used in atomic services since API version 11. 134 135**System capability**: SystemCapability.Applications.Contacts 136 137**Parameters** 138 139| Name | Type | Mandatory| Description | 140| ----------- | ------------------------- | ---- | ------------------------------------------ | 141| phoneNumber | string | Yes | Phone number. | 142| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 143 144**Error codes** 145 146For details about the error codes, see [ohos.telephony (Telephony) Error Codes](errorcode-telephony.md) and [Universal Error Codes](../errorcode-universal.md). 147 148| ID| Error Message | 149| -------- | -------------------------------------------- | 150| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types;| 151| 8300001 | Invalid parameter value. | 152| 8300002 | Operation failed. Cannot connect to service. | 153| 8300003 | System internal error. | 154| 8300999 | Unknown error code. | 155 156**Example** 157 158```ts 159import { BusinessError } from '@kit.BasicServicesKit'; 160 161call.makeCall("138xxxxxxxx", (err: BusinessError) => { 162 if (err) { 163 console.error(`makeCall fail, err->${JSON.stringify(err)}`); 164 } else { 165 console.log(`makeCall success`); 166 } 167}); 168``` 169 170 171## call.makeCall<sup>7+</sup> 172 173makeCall\(phoneNumber: string\): Promise\<void\> 174 175Launches the call screen and displays the dialed number. This API uses a promise to return the result. This API can be called only in a UIAbility. 176 177**Atomic service API**: This API can be used in atomic services since API version 11. 178 179**System capability**: SystemCapability.Applications.Contacts 180 181**Parameters** 182 183| Name | Type | Mandatory| Description | 184| ----------- | ------ | ---- | ---------- | 185| phoneNumber | string | Yes | Phone number.| 186 187**Return value** 188 189| Type | Description | 190| ------------------- | --------------------------------- | 191| Promise<void> | Promise used to return the result.| 192 193**Error codes** 194 195For details about the error codes, see [ohos.telephony (Telephony) Error Codes](errorcode-telephony.md) and [Universal Error Codes](../errorcode-universal.md). 196 197| ID| Error Message | 198| -------- | -------------------------------------------- | 199| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types;| 200| 8300001 | Invalid parameter value. | 201| 8300002 | Operation failed. Cannot connect to service. | 202| 8300003 | System internal error. | 203| 8300999 | Unknown error code. | 204 205**Example** 206 207```ts 208import { BusinessError } from '@kit.BasicServicesKit'; 209 210call.makeCall("138xxxxxxxx").then(() => { 211 console.log(`makeCall success`); 212}).catch((err: BusinessError) => { 213 console.error(`makeCall fail, promise: err->${JSON.stringify(err)}`); 214}); 215``` 216 217## call.makeCall<sup>12+</sup> 218 219makeCall\(context: Context, phoneNumber: string\): Promise\<void\> 220 221Launches the call screen and displays the dialed number. This API uses a promise to return the result. You need to declare the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission if you want to call the API in the background. 222 223**Atomic service API**: This API can be used in atomic services since API version 12. 224 225**System capability**: SystemCapability.Applications.Contacts 226 227**Parameters** 228 229| Name | Type | Mandatory| Description | 230| ----------- | ------ | ---- | ---------- | 231| context | Context | Yes | Application context.| 232| phoneNumber | string | Yes | Phone number.| 233 234**Return value** 235 236| Type | Description | 237| ------------------- | --------------------------------- | 238| Promise<void> | Promise used to return the result.| 239 240**Error codes** 241 242For details about the error codes, see [ohos.telephony (Telephony) Error Codes](errorcode-telephony.md) and [Universal Error Codes](../errorcode-universal.md). 243 244| ID| Error Message | 245| -------- | -------------------------------------------- | 246| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types;| 247| 8300002 | Operation failed. Cannot connect to service. | 248| 8300003 | System internal error. | 249 250**Example** 251 252```ts 253import { BusinessError } from '@kit.BasicServicesKit'; 254// Obtain the application context. 255let context = getContext(this) as Context; 256call.makeCall(context, "138xxxxxxxx").then(() => { 257 console.log(`makeCall success`); 258}).catch((err: BusinessError) => { 259 console.error(`makeCall fail, promise: err->${JSON.stringify(err)}`); 260}); 261``` 262 263## call.hasCall 264 265hasCall\(callback: AsyncCallback\<boolean\>\): void 266 267Checks whether a call is in progress. This API uses an asynchronous callback to return the result. 268 269**System capability**: SystemCapability.Telephony.CallManager 270 271**Parameters** 272 273| Name | Type | Mandatory| Description | 274| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 275| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** indicates that a call is in progress, and the value **false** indicates the opposite.| 276 277**Example** 278 279```ts 280import { BusinessError } from '@kit.BasicServicesKit'; 281 282call.hasCall((err: BusinessError, data: boolean) => { 283 if (err) { 284 console.error(`hasCall fail, err->${JSON.stringify(err)}`); 285 } else { 286 console.log(`hasCall success, data->${JSON.stringify(data)}`); 287 } 288}); 289``` 290 291 292## call.hasCall 293 294hasCall\(\): Promise\<boolean\> 295 296Checks whether a call is in progress. This API uses a promise to return the result. 297 298**System capability**: SystemCapability.Telephony.CallManager 299 300**Return value** 301 302| Type | Description | 303| ---------------------- | --------------------------------------- | 304| Promise<boolean> | Promise used to return the result. The value **true** indicates that a call is in progress, and the value **false** indicates the opposite.| 305 306**Example** 307 308```ts 309import { BusinessError } from '@kit.BasicServicesKit'; 310 311call.hasCall().then(() => { 312 console.log(`hasCall success`); 313}).catch((err: BusinessError) => { 314 console.error(`hasCall fail, promise: err->${JSON.stringify(err)}`); 315}); 316``` 317 318## call.hasCallSync<sup>10+</sup> 319 320hasCallSync\(\): boolean 321 322Checks whether a call is in progress. 323 324**System capability**: SystemCapability.Telephony.CallManager 325 326**Return value** 327 328| Type | Description | 329| ---------------------- |-------------| 330| boolean | Promise used to return the result. The value **true** indicates that a call is in progress, and the value **false** indicates the opposite.| 331 332**Example** 333 334```ts 335let hasCall: boolean = call.hasCallSync(); 336console.log(`hasCallSync success, has call is ` + hasCall); 337``` 338 339 340## call.getCallState 341 342getCallState\(callback: AsyncCallback\<CallState\>\): void 343 344Obtains the call status. This API uses an asynchronous callback to return the result. 345 346**System capability**: SystemCapability.Telephony.CallManager 347 348**Parameters** 349 350| Name | Type | Mandatory| Description | 351| -------- | -------------------------------------------- | ---- | ------------------------------------ | 352| callback | AsyncCallback<[CallState](#callstate)> | Yes | Callback used to return the result.| 353 354**Example** 355 356```ts 357import { BusinessError } from '@kit.BasicServicesKit'; 358 359call.getCallState((err: BusinessError, data: call.CallState) => { 360 if (err) { 361 console.error(`getCallState fail, err->${JSON.stringify(err)}`); 362 } else { 363 console.log(`getCallState success, data->${JSON.stringify(data)}`); 364 } 365}); 366``` 367 368 369## call.getCallState 370 371getCallState\(\): Promise\<CallState\> 372 373Obtains the call status. This API uses a promise to return the result. 374 375**System capability**: SystemCapability.Telephony.CallManager 376 377**Return value** 378 379| Type | Description | 380| -------------------------------------- | --------------------------------------- | 381| Promise<[CallState](#callstate)> | Promise used to return the result.| 382 383**Example** 384 385```ts 386import { BusinessError } from '@kit.BasicServicesKit'; 387 388call.getCallState().then((data: call.CallState) => { 389 console.log(`getCallState success, promise: data->${JSON.stringify(data)}`); 390}).catch((err: BusinessError) => { 391 console.error(`getCallState fail, promise: err->${JSON.stringify(err)}`); 392}); 393``` 394 395## call.getCallStateSync<sup>10+</sup> 396 397getCallStateSync\(\): CallState 398 399Obtains the call status. 400 401**System capability**: SystemCapability.Telephony.CallManager 402 403**Return value** 404 405| Type | Description | 406| ------------------------------------- |-------------| 407| [CallState](#callstate) | Promise used to return the result.| 408 409**Example** 410 411```ts 412let callState: call.CallState = call.getCallStateSync(); 413console.log(`the call state is:` + callState); 414``` 415 416## call.hasVoiceCapability<sup>7+</sup> 417 418hasVoiceCapability\(\): boolean 419 420Checks whether a device supports voice calls. 421 422**System capability**: SystemCapability.Telephony.CallManager 423 424**Return value** 425 426| Type | Description | 427| ------- | ------------------------------------------------------------ | 428| boolean | Result indicating whether the device supports voice calls. The value **true** indicates yes, and the value **false** indicates no.| 429 430```ts 431let result: boolean = call.hasVoiceCapability(); 432console.log(`hasVoiceCapability: ${JSON.stringify(result)}`); 433``` 434 435## call.isEmergencyPhoneNumber<sup>7+</sup> 436 437isEmergencyPhoneNumber\(phoneNumber: string, callback: AsyncCallback\<boolean\>\): void 438 439Checks whether the called number is an emergency number. This API uses an asynchronous callback to return the result. 440 441**System capability**: SystemCapability.Telephony.CallManager 442 443**Parameters** 444 445| Name | Type | Mandatory| Description | 446| ----------- | ---------------------------- | ---- | ------------------------------------------------------------ | 447| phoneNumber | string | Yes | Phone number. | 448| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** indicates that the called number is an emergency number, and the value **false** indicates the opposite.| 449 450**Error codes** 451 452For details about the error codes, see [ohos.telephony (Telephony) Error Codes](errorcode-telephony.md) and [Universal Error Codes](../errorcode-universal.md). 453 454| ID| Error Message | 455| -------- | -------------------------------------------- | 456| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types;| 457| 8300001 | Invalid parameter value. | 458| 8300002 | Operation failed. Cannot connect to service. | 459| 8300003 | System internal error. | 460| 8300999 | Unknown error code. | 461 462**Example** 463 464```ts 465import { BusinessError } from '@kit.BasicServicesKit'; 466 467call.isEmergencyPhoneNumber("138xxxxxxxx", (err: BusinessError, data: boolean) => { 468 if (err) { 469 console.error(`isEmergencyPhoneNumber fail, err->${JSON.stringify(err)}`); 470 } else { 471 console.log(`isEmergencyPhoneNumber success, data->${JSON.stringify(data)}`); 472 } 473}); 474``` 475 476 477## call.isEmergencyPhoneNumber<sup>7+</sup> 478 479isEmergencyPhoneNumber\(phoneNumber: string, options: EmergencyNumberOptions, callback: AsyncCallback\<boolean\>\): void 480 481Checks whether the called number is an emergency number based on the phone number. This API uses an asynchronous callback to return the result. 482 483**System capability**: SystemCapability.Telephony.CallManager 484 485**Parameters** 486 487| Name | Type | Mandatory| Description | 488| ----------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ | 489| phoneNumber | string | Yes | Phone number. | 490| options | [EmergencyNumberOptions](#emergencynumberoptions7) | Yes | Emergency number options. | 491| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** indicates that the called number is an emergency number, and the value **false** indicates the opposite.| 492 493**Error codes** 494 495For details about the error codes, see [ohos.telephony (Telephony) Error Codes](errorcode-telephony.md) and [Universal Error Codes](../errorcode-universal.md). 496 497| ID| Error Message | 498| -------- | -------------------------------------------- | 499| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types;| 500| 8300001 | Invalid parameter value. | 501| 8300002 | Operation failed. Cannot connect to service. | 502| 8300003 | System internal error. | 503| 8300999 | Unknown error code. | 504 505**Example** 506 507```ts 508import { BusinessError } from '@kit.BasicServicesKit'; 509 510let options: call.EmergencyNumberOptions = {slotId: 1} 511call.isEmergencyPhoneNumber("112", options, (err: BusinessError, data: boolean) => { 512 if (err) { 513 console.error(`isEmergencyPhoneNumber fail, err->${JSON.stringify(err)}`); 514 } else { 515 console.log(`isEmergencyPhoneNumber success, data->${JSON.stringify(data)}`); 516 } 517}); 518``` 519 520 521## call.isEmergencyPhoneNumber<sup>7+</sup> 522 523isEmergencyPhoneNumber\(phoneNumber: string, options?: EmergencyNumberOptions\): Promise\<boolean\> 524 525Checks whether the called number is an emergency number based on the phone number. This API uses a promise to return the result. 526 527**System capability**: SystemCapability.Telephony.CallManager 528 529**Parameters** 530 531| Name | Type | Mandatory| Description | 532| ----------- | -------------------------------------------------- | ---- | -------------- | 533| phoneNumber | string | Yes | Phone number. | 534| options | [EmergencyNumberOptions](#emergencynumberoptions7) | No | Emergency number options.| 535 536**Return value** 537 538| Type | Description | 539| ---------------------- | --------------------------------------------------- | 540| Promise<boolean> | Promise used to return the result. The value **true** indicates that the called number is an emergency number, and the value **false** indicates the opposite.| 541 542**Error codes** 543 544For details about the error codes, see [ohos.telephony (Telephony) Error Codes](errorcode-telephony.md) and [Universal Error Codes](../errorcode-universal.md). 545 546| ID| Error Message | 547| -------- | -------------------------------------------- | 548| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types;| 549| 8300001 | Invalid parameter value. | 550| 8300002 | Operation failed. Cannot connect to service. | 551| 8300003 | System internal error. | 552| 8300999 | Unknown error code. | 553 554**Example** 555 556```ts 557import { BusinessError } from '@kit.BasicServicesKit'; 558 559let options: call.EmergencyNumberOptions = {slotId: 1} 560call.isEmergencyPhoneNumber("138xxxxxxxx", options).then((data: boolean) => { 561 console.log(`isEmergencyPhoneNumber success, promise: data->${JSON.stringify(data)}`); 562}).catch((err: BusinessError) => { 563 console.error(`isEmergencyPhoneNumber fail, promise: err->${JSON.stringify(err)}`); 564}); 565``` 566 567## call.formatPhoneNumber<sup>7+</sup> 568 569formatPhoneNumber\(phoneNumber: string, callback: AsyncCallback\<string\>\): void 570 571Formats a phone number. This API uses an asynchronous callback to return the result. 572 573A formatted phone number is a standard numeric string, for example, 555 0100. 574 575**System capability**: SystemCapability.Telephony.CallManager 576 577**Parameters** 578 579| Name | Type | Mandatory| Description | 580| ----------- | --------------------------- | ---- | ------------------------------------ | 581| phoneNumber | string | Yes | Phone number. | 582| callback | AsyncCallback<string> | Yes | Callback used to return the result.| 583 584**Error codes** 585 586For details about the error codes, see [ohos.telephony (Telephony) Error Codes](errorcode-telephony.md) and [Universal Error Codes](../errorcode-universal.md). 587 588| ID| Error Message | 589| -------- | -------------------------------------------- | 590| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types;| 591| 8300001 | Invalid parameter value. | 592| 8300002 | Operation failed. Cannot connect to service. | 593| 8300003 | System internal error. | 594| 8300999 | Unknown error code. | 595 596**Example** 597 598```ts 599import { BusinessError } from '@kit.BasicServicesKit'; 600 601call.formatPhoneNumber("138xxxxxxxx", (err: BusinessError, data: string) => { 602 if (err) { 603 console.error(`formatPhoneNumber fail, err->${JSON.stringify(err)}`); 604 } else { 605 console.log(`formatPhoneNumber success, data->${JSON.stringify(data)}`); 606 } 607}); 608``` 609 610## call.formatPhoneNumber<sup>7+</sup> 611 612formatPhoneNumber\(phoneNumber: string, options: NumberFormatOptions, callback: AsyncCallback\<string\>\): void 613 614Formats a phone number based on specified formatting options. This API uses an asynchronous callback to return the result. 615 616A formatted phone number is a standard numeric string, for example, 555 0100. 617 618**System capability**: SystemCapability.Telephony.CallManager 619 620**Parameters** 621 622| Name | Type | Mandatory| Description | 623| ----------- | -------------------------------------------- | ---- | ------------------------------------ | 624| phoneNumber | string | Yes | Phone number. | 625| options | [NumberFormatOptions](#numberformatoptions7) | Yes | Number formatting options, for example, country code. | 626| callback | AsyncCallback<string> | Yes | Callback used to return the result.| 627 628**Error codes** 629 630For details about the error codes, see [ohos.telephony (Telephony) Error Codes](errorcode-telephony.md) and [Universal Error Codes](../errorcode-universal.md). 631 632| ID| Error Message | 633| -------- | -------------------------------------------- | 634| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types;| 635| 8300001 | Invalid parameter value. | 636| 8300002 | Operation failed. Cannot connect to service. | 637| 8300003 | System internal error. | 638| 8300999 | Unknown error code. | 639 640**Example** 641 642```ts 643import { BusinessError } from '@kit.BasicServicesKit'; 644 645let options: call.NumberFormatOptions = { 646 countryCode: "CN" 647} 648call.formatPhoneNumber("138xxxxxxxx", options, (err: BusinessError, data: string) => { 649 if (err) { 650 console.error(`formatPhoneNumber fail, err->${JSON.stringify(err)}`); 651 } else { 652 console.log(`formatPhoneNumber success, data->${JSON.stringify(data)}`); 653 } 654}); 655``` 656 657 658## call.formatPhoneNumber<sup>7+</sup> 659 660formatPhoneNumber\(phoneNumber: string, options?: NumberFormatOptions\): Promise\<string\> 661 662Formats a phone number based on specified formatting options. This API uses a promise to return the result. 663 664A formatted phone number is a standard numeric string, for example, 555 0100. 665 666**System capability**: SystemCapability.Telephony.CallManager 667 668**Parameters** 669 670| Name | Type | Mandatory| Description | 671| ----------- | -------------------------------------------- | ---- | ---------------------- | 672| phoneNumber | string | Yes | Phone number. | 673| options | [NumberFormatOptions](#numberformatoptions7) | No | Number formatting options, for example, country code.| 674 675**Return value** 676 677| Type | Description | 678| --------------------- | ------------------------------------------- | 679| Promise<string> | Promise used to return the result.| 680 681**Error codes** 682 683For details about the error codes, see [ohos.telephony (Telephony) Error Codes](errorcode-telephony.md) and [Universal Error Codes](../errorcode-universal.md). 684 685| ID| Error Message | 686| -------- | -------------------------------------------- | 687| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types;| 688| 8300001 | Invalid parameter value. | 689| 8300002 | Operation failed. Cannot connect to service. | 690| 8300003 | System internal error. | 691| 8300999 | Unknown error code. | 692 693**Example** 694 695```ts 696import { BusinessError } from '@kit.BasicServicesKit'; 697 698let options: call.NumberFormatOptions = { 699 countryCode: "CN" 700} 701call.formatPhoneNumber("138xxxxxxxx", options).then((data: string) => { 702 console.log(`formatPhoneNumber success, promise: data->${JSON.stringify(data)}`); 703}).catch((err: BusinessError) => { 704 console.error(`formatPhoneNumber fail, promise: err->${JSON.stringify(err)}`); 705}); 706``` 707 708## call.formatPhoneNumberToE164<sup>7+</sup> 709 710formatPhoneNumberToE164\(phoneNumber: string, countryCode: string, callback: AsyncCallback\<string\>\): void 711 712Converts a phone number into the E.164 format. This API uses an asynchronous callback to return the result. 713 714The phone number must match the specified country code. For example, for a China phone number, the country code must be **CN**. Otherwise, **null** will be returned. 715 716**System capability**: SystemCapability.Telephony.CallManager 717 718**Parameters** 719 720| Name | Type | Mandatory| Description | 721| ----------- | --------------------------- | ---- | ----------------------------------------------------- | 722| phoneNumber | string | Yes | Phone number. | 723| countryCode | string | Yes | Country code, for example, **CN** (China). All country codes are supported. | 724| callback | AsyncCallback<string> | Yes | Callback used to return the result.| 725 726**Error codes** 727 728For details about the error codes, see [ohos.telephony (Telephony) Error Codes](errorcode-telephony.md) and [Universal Error Codes](../errorcode-universal.md). 729 730| ID| Error Message | 731| -------- | -------------------------------------------- | 732| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types;| 733| 8300001 | Invalid parameter value. | 734| 8300002 | Operation failed. Cannot connect to service. | 735| 8300003 | System internal error. | 736| 8300999 | Unknown error code. | 737 738**Example** 739 740```ts 741import { BusinessError } from '@kit.BasicServicesKit'; 742 743call.formatPhoneNumberToE164("138xxxxxxxx", "CN", (err: BusinessError, data: string) => { 744 if (err) { 745 console.error(`formatPhoneNumberToE164 fail, err->${JSON.stringify(err)}`); 746 } else { 747 console.log(`formatPhoneNumberToE164 success, data->${JSON.stringify(data)}`); 748 } 749}); 750``` 751 752 753## call.formatPhoneNumberToE164<sup>7+</sup> 754 755formatPhoneNumberToE164\(phoneNumber: string, countryCode: string\): Promise\<string\> 756 757Converts a phone number into the E.164 format. This API uses a promise to return the result. 758 759The phone number must match the specified country code. For example, for a China phone number, the country code must be **CN**. Otherwise, **null** will be returned. 760 761All country codes are supported. 762 763**System capability**: SystemCapability.Telephony.CallManager 764 765**Parameters** 766 767| Name | Type | Mandatory| Description | 768| ----------- | ------ | ---- | ---------------------------------------- | 769| phoneNumber | string | Yes | Phone number. | 770| countryCode | string | Yes | Country code, for example, **CN** (China). All country codes are supported.| 771 772**Return value** 773 774| Type | Description | 775| --------------------- | ------------------------------------------------------------ | 776| Promise<string> | Promise used to return the result.| 777 778**Error codes** 779 780For details about the error codes, see [ohos.telephony (Telephony) Error Codes](errorcode-telephony.md) and [Universal Error Codes](../errorcode-universal.md). 781 782| ID| Error Message | 783| -------- | -------------------------------------------- | 784| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types;| 785| 8300001 | Invalid parameter value. | 786| 8300002 | Operation failed. Cannot connect to service. | 787| 8300003 | System internal error. | 788| 8300999 | Unknown error code. | 789 790**Example** 791 792```ts 793import { BusinessError } from '@kit.BasicServicesKit'; 794 795call.formatPhoneNumberToE164("138xxxxxxxx", "CN").then((data: string) => { 796 console.log(`formatPhoneNumberToE164 success, promise: data->${JSON.stringify(data)}`); 797}).catch((err: BusinessError) => { 798 console.error(`formatPhoneNumberToE164 fail, promise: err->${JSON.stringify(err)}`); 799}); 800``` 801 802## DialOptions 803 804Provides an option for determining whether a call is a video call. 805 806**System capability**: SystemCapability.Telephony.CallManager 807 808| Name | Type | Mandatory| Description | 809| ------------------------ | ---------------------------------- | ---- | ----------------------------------------------------------------------------------------------- | 810| extras | boolean | No | Whether the call is a video call. <br>- **true**: video call<br>- **false** (default): voice call | 811 812## CallState 813 814Enumerates call states. 815 816**System capability**: SystemCapability.Telephony.CallManager 817 818| Name | Value | Description | 819| ------------------ | ---- | ------------------------------------------------------------ | 820| CALL_STATE_UNKNOWN | -1 | The call status fails to be obtained and is unknown. | 821| CALL_STATE_IDLE | 0 | No call is in progress. | 822| CALL_STATE_RINGING | 1 | The call is in the ringing or waiting state. | 823| CALL_STATE_OFFHOOK | 2 | At least one call is in dialing, active, or on hold, and no new incoming call is ringing or waiting.| 824| CALL_STATE_ANSWERED<sup>11+</sup> | 3 | The incoming call is answered.| 825 826## EmergencyNumberOptions<sup>7+</sup> 827 828Provides an option for determining whether a number is an emergency number for the SIM card in the specified slot. 829 830**System capability**: SystemCapability.Telephony.CallManager 831 832| Name | Type | Mandatory| Description | 833| ------ | ------ | ---- | ---------------------------------------------- | 834| slotId | number | No | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 835 836## NumberFormatOptions<sup>7+</sup> 837 838Provides an option for number formatting. 839 840**System capability**: SystemCapability.Telephony.CallManager 841 842| Name | Type | Mandatory| Description | 843| ----------- | ------ | ---- | ---------------------------------------------------------- | 844| countryCode | string | No | Country code, for example, **CN** (China). All country codes are supported. The default value is **CN**.| 845