js-apis-call.md 20.7 KB
Newer Older
S
shawn_he 已提交
1 2
# Call

S
shawn_he 已提交
3 4 5 6 7
The call module provides call management functions, including making calls, redirecting to the dial screen, obtaining the call status, and formatting phone numbers.

To subscribe to the call status, use [`observer.on('callStateChange')`](js-apis-observer.md#observeroncallstatechange).

>**NOTE**<br>
Z
zengyawen 已提交
8
>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.
S
shawn_he 已提交
9 10 11 12


## Modules to Import

S
shawn_he 已提交
13
```js
S
shawn_he 已提交
14 15 16
import call from '@ohos.telephony.call';
```

S
shawn_he 已提交
17
## call.dial
S
shawn_he 已提交
18 19 20

dial\(phoneNumber: string, callback: AsyncCallback<boolean\>\): void

S
shawn_he 已提交
21
Initiates a call. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
22

S
shawn_he 已提交
23 24 25
**Required permission**: ohos.permission.PLACE\_CALL (a system permission)

**System capability**: SystemCapability.Telephony.CallManager
S
shawn_he 已提交
26

S
shawn_he 已提交
27
**Parameters**
S
shawn_he 已提交
28

O
openharmony_ci 已提交
29
| Name     | Type                        | Mandatory| Description                             |
S
shawn_he 已提交
30
| ----------- | ---------------------------- | ---- | --------------------------------------- |
O
openharmony_ci 已提交
31 32
| phoneNumber | string                       | Yes  | Phone number.                           |
| callback    | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result.<br>- **true**: success<br>- **false**: failure |
S
shawn_he 已提交
33 34 35

**Example**

S
shawn_he 已提交
36
```js
S
shawn_he 已提交
37 38 39 40
call.dial("138xxxxxxxx", (err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
41 42


S
shawn_he 已提交
43
## call.dial
S
shawn_he 已提交
44 45 46

dial\(phoneNumber: string, options: DialOptions, callback: AsyncCallback<boolean\>\): void

S
shawn_he 已提交
47
Initiates a call. You can set call options as needed. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
48

S
shawn_he 已提交
49 50 51
**Required permission**: ohos.permission.PLACE\_CALL (a system permission)

**System capability**: SystemCapability.Telephony.CallManager
S
shawn_he 已提交
52

S
shawn_he 已提交
53
**Parameters**
S
shawn_he 已提交
54

O
openharmony_ci 已提交
55
| Name     | Type                        | Mandatory| Description                             |
S
shawn_he 已提交
56
| ----------- | ---------------------------- | ---- | --------------------------------------- |
O
openharmony_ci 已提交
57
| phoneNumber | string                       | Yes  | Phone number.                           |
S
shawn_he 已提交
58
| options     | [DialOptions](#dialoptions)  | Yes  | Call option, which indicates whether the call is a voice call or video call. |
O
openharmony_ci 已提交
59
| callback    | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result.<br>- **true**: success<br>- **false**: failure |
S
shawn_he 已提交
60

S
shawn_he 已提交
61
**Example**
S
shawn_he 已提交
62

S
shawn_he 已提交
63
```js
S
shawn_he 已提交
64 65 66 67 68 69
call.dial("138xxxxxxxx", {
    extras: false
}, (err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
70 71


S
shawn_he 已提交
72
## call.dial
S
shawn_he 已提交
73 74 75

dial\(phoneNumber: string, options?: DialOptions\): Promise<boolean\>

S
shawn_he 已提交
76
Initiates a call. You can set call options as needed. This API uses a promise to return the result.
S
shawn_he 已提交
77

S
shawn_he 已提交
78 79 80
**Required permission**: ohos.permission.PLACE\_CALL (a system permission)

**System capability**: SystemCapability.Telephony.CallManager
S
shawn_he 已提交
81

S
shawn_he 已提交
82
**Parameters**
S
shawn_he 已提交
83

O
openharmony_ci 已提交
84
| Name     | Type                       | Mandatory| Description                            |
S
shawn_he 已提交
85
| ----------- | --------------------------- | ---- | -------------------------------------- |
O
openharmony_ci 已提交
86
| phoneNumber | string                      | Yes  | Phone number.                          |
S
shawn_he 已提交
87
| options     | [DialOptions](#dialoptions) | Yes  | Call option, which indicates whether the call is a voice call or video call.|
S
shawn_he 已提交
88

S
shawn_he 已提交
89
**Return value**
S
shawn_he 已提交
90

O
openharmony_ci 已提交
91 92 93
| Type                   | Description                                                       |
| ---------------------- | ---------------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.<br>- **true**: success<br>- **false**: failure |
S
shawn_he 已提交
94

S
shawn_he 已提交
95
**Example**
S
shawn_he 已提交
96

S
shawn_he 已提交
97
```js
S
shawn_he 已提交
98 99 100 101 102 103 104 105 106
let promise = call.dial("138xxxxxxxx", {
    extras: false
});
promise.then(data => {
    console.log(`dial success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
    console.error(`dial fail, promise: err->${JSON.stringify(err)}`);
});
```
S
shawn_he 已提交
107

S
shawn_he 已提交
108
## call.makeCall<sup>7+</sup>
S
shawn_he 已提交
109

S
shawn_he 已提交
110
makeCall(phoneNumber: string, callback: AsyncCallback\<void\>): void
S
shawn_he 已提交
111

S
shawn_he 已提交
112
Launches the call screen and displays the dialed number. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
113

S
shawn_he 已提交
114
**System capability**: SystemCapability.Applications.Contacts
S
shawn_he 已提交
115 116 117

**Parameters**

S
shawn_he 已提交
118
| Name     | Type                     | Mandatory| Description                                      |
S
shawn_he 已提交
119 120 121 122 123 124
| ----------- | ------------------------- | ---- | ------------------------------------------ |
| phoneNumber | string                    | Yes  | Phone number.                                |
| callback    | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
125
```js
S
shawn_he 已提交
126 127 128 129 130 131
call.makeCall("138xxxxxxxx", err => { 
    console.log(`makeCall callback: err->${JSON.stringify(err)}`); 
});
```


S
shawn_he 已提交
132
## call.makeCall<sup>7+</sup>
S
shawn_he 已提交
133

S
shawn_he 已提交
134
makeCall(phoneNumber: string): Promise\<void\>
S
shawn_he 已提交
135

S
shawn_he 已提交
136
Launches the call screen and displays the dialed number. This API uses a promise to return the result.
S
shawn_he 已提交
137

S
shawn_he 已提交
138
**System capability**: SystemCapability.Applications.Contacts
S
shawn_he 已提交
139 140 141

**Parameters**

S
shawn_he 已提交
142
| Name     | Type  | Mandatory| Description      |
S
shawn_he 已提交
143 144 145
| ----------- | ------ | ---- | ---------- |
| phoneNumber | string | Yes  | Phone number.|

S
shawn_he 已提交
146
**Return value**
S
shawn_he 已提交
147 148 149 150 151 152 153

| Type               | Description                             |
| ------------------- | --------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**

S
shawn_he 已提交
154
```js
S
shawn_he 已提交
155 156 157 158 159 160 161 162
let promise = call.makeCall("138xxxxxxxx"); 
promise.then(() => { 
    console.log(`makeCall success`); 
}).catch(err => { 
    console.error(`makeCall fail, promise: err->${JSON.stringify(err)}`); 
});
```

S
shawn_he 已提交
163
## call.hasCall
S
shawn_he 已提交
164 165 166

hasCall\(callback: AsyncCallback<boolean\>\): void

S
shawn_he 已提交
167
Checks whether a call is in progress. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
168

S
shawn_he 已提交
169 170
**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
171
**Parameters**
S
shawn_he 已提交
172

S
shawn_he 已提交
173
| Name  | Type                        | Mandatory| Description                                                        |
S
shawn_he 已提交
174
| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
S
shawn_he 已提交
175
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. Callback used to return the result.<br>- **true**: A call is in progress.<br>- **false**: No call is in progress.|
S
shawn_he 已提交
176

S
shawn_he 已提交
177
**Example**
S
shawn_he 已提交
178

S
shawn_he 已提交
179
```js
S
shawn_he 已提交
180 181 182 183
call.hasCall((err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
184 185


S
shawn_he 已提交
186
## call.hasCall
S
shawn_he 已提交
187 188 189

hasCall\(\): Promise<boolean\>

S
shawn_he 已提交
190
Checks whether a call is in progress. This API uses a promise to return the result.
S
shawn_he 已提交
191

S
shawn_he 已提交
192 193
**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
194
**Return value**
S
shawn_he 已提交
195

S
shawn_he 已提交
196
| Type                  | Description                                   |
S
shawn_he 已提交
197 198
| ---------------------- | --------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|
S
shawn_he 已提交
199

S
shawn_he 已提交
200
**Example**
S
shawn_he 已提交
201

S
shawn_he 已提交
202
```js
S
shawn_he 已提交
203 204 205 206 207 208 209
let promise = call.hasCall();
promise.then(data => {
    console.log(`hasCall success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
    console.error(`hasCall fail, promise: err->${JSON.stringify(err)}`);
});
```
S
shawn_he 已提交
210 211


S
shawn_he 已提交
212
## call.getCallState
S
shawn_he 已提交
213 214 215

getCallState\(callback: AsyncCallback<CallState\>\): void

S
shawn_he 已提交
216
Obtains the call status. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
217

S
shawn_he 已提交
218 219
**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
220
**Parameters**
S
shawn_he 已提交
221

S
shawn_he 已提交
222
| Name  | Type                                        | Mandatory| Description                                |
S
shawn_he 已提交
223
| -------- | -------------------------------------------- | ---- | ------------------------------------ |
S
shawn_he 已提交
224
| callback | AsyncCallback&lt;[CallState](#callstate)&gt; | Yes  | Callback used to return the result.|
S
shawn_he 已提交
225

S
shawn_he 已提交
226
**Example**
S
shawn_he 已提交
227

S
shawn_he 已提交
228
```js
S
shawn_he 已提交
229 230 231 232
call.getCallState((err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
233 234


S
shawn_he 已提交
235
## call.getCallState
S
shawn_he 已提交
236 237 238

getCallState\(\): Promise<CallState\>

S
shawn_he 已提交
239
Obtains the call status. This API uses a promise to return the result.
S
shawn_he 已提交
240

S
shawn_he 已提交
241 242
**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
243
**Return value**
S
shawn_he 已提交
244

S
shawn_he 已提交
245 246
| Type                                  | Description                                   |
| -------------------------------------- | --------------------------------------- |
S
shawn_he 已提交
247
| Promise&lt;[CallState](#callstate)&gt; | Promise used to return the result.|
S
shawn_he 已提交
248

S
shawn_he 已提交
249
**Example**
S
shawn_he 已提交
250

S
shawn_he 已提交
251
```js
S
shawn_he 已提交
252 253 254 255 256 257 258
let promise = call.getCallState();
promise.then(data => {
    console.log(`getCallState success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
    console.error(`getCallState fail, promise: err->${JSON.stringify(err)}`);
});
```
S
shawn_he 已提交
259

S
shawn_he 已提交
260
## call.hasVoiceCapability<sup>7+</sup>
S
shawn_he 已提交
261 262 263

hasVoiceCapability(): boolean

S
shawn_he 已提交
264
Checks whether a device supports voice calls.
S
shawn_he 已提交
265 266 267

**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
268
**Return value**
S
shawn_he 已提交
269 270 271 272 273

| Type   | Description                                                        |
| ------- | ------------------------------------------------------------ |
| boolean | - **true**: The device supports voice calls.<br>- **false**: The device does not support voice calls.|

S
shawn_he 已提交
274
```js
S
shawn_he 已提交
275 276 277 278
let result = call.hasVoiceCapability(); 
console.log(`hasVoiceCapability: ${JSON.stringify(result)}`);
```

S
shawn_he 已提交
279
## call.isEmergencyPhoneNumber<sup>7+</sup>
S
shawn_he 已提交
280 281 282

isEmergencyPhoneNumber\(phoneNumber: string, callback: AsyncCallback<boolean\>\): void

S
shawn_he 已提交
283
Checks whether the called number is an emergency number. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
284

S
shawn_he 已提交
285 286
**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
287
**Parameters**
S
shawn_he 已提交
288

S
shawn_he 已提交
289
| Name     | Type                        | Mandatory| Description                                                        |
S
shawn_he 已提交
290
| ----------- | ---------------------------- | ---- | ------------------------------------------------------------ |
S
shawn_he 已提交
291
| phoneNumber | string                       | Yes  | Phone number.                                                  |
S
shawn_he 已提交
292
| callback    | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result.<br> - **true**: The called number is an emergency number.<br>- **false**: The called number is not an emergency number.|
S
shawn_he 已提交
293

S
shawn_he 已提交
294
**Example**
S
shawn_he 已提交
295

S
shawn_he 已提交
296
```js
S
shawn_he 已提交
297 298 299 300
call.isEmergencyPhoneNumber("138xxxxxxxx", (err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
301 302


S
shawn_he 已提交
303
## call.isEmergencyPhoneNumber<sup>7+</sup>
S
shawn_he 已提交
304 305 306

isEmergencyPhoneNumber\(phoneNumber: string, options: EmergencyNumberOptions, callback: AsyncCallback<boolean\>\): void

S
shawn_he 已提交
307
Checks whether the called number is an emergency number based on the phone number. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
308

S
shawn_he 已提交
309 310
**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
311
**Parameters**
S
shawn_he 已提交
312

S
shawn_he 已提交
313 314 315 316
| Name     | Type                                              | Mandatory| Description                                                       |
| ----------- | -------------------------------------------------- | ---- | -------------------------------------------- |
| phoneNumber | string                                             | Yes  | Phone number.                                                 |
| options     | [EmergencyNumberOptions](#emergencynumberoptions7) | Yes  | Phone number option.        |
S
shawn_he 已提交
317
| callback    | AsyncCallback&lt;boolean&gt;                       | Yes  | Callback used to return the result.<br> - **true**: The called number is an emergency number.<br>- **false**: The called number is not an emergency number.|
S
shawn_he 已提交
318

S
shawn_he 已提交
319
**Example**
S
shawn_he 已提交
320

S
shawn_he 已提交
321
```js
S
shawn_he 已提交
322 323 324 325
call.isEmergencyPhoneNumber("112", {slotId: 1}, (err, value) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
326 327


S
shawn_he 已提交
328
## call.isEmergencyPhoneNumber<sup>7+</sup>
S
shawn_he 已提交
329 330 331

isEmergencyPhoneNumber\(phoneNumber: string, options?: EmergencyNumberOptions\): Promise<boolean\>

S
shawn_he 已提交
332
Checks whether the called number is an emergency number based on the phone number. This API uses a promise to return the result.
S
shawn_he 已提交
333

S
shawn_he 已提交
334 335
**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
336
**Parameters**
S
shawn_he 已提交
337

S
shawn_he 已提交
338 339 340
| Name     | Type                                              | Mandatory| Description          |
| ----------- | -------------------------------------------------- | ---- | -------------- |
| phoneNumber | string                                             | Yes  | Phone number.    |
S
shawn_he 已提交
341
| options     | [EmergencyNumberOptions](#emergencynumberoptions7) | Yes  | Phone number option.|
S
shawn_he 已提交
342

S
shawn_he 已提交
343
**Return value**
S
shawn_he 已提交
344

S
shawn_he 已提交
345
| Type                  | Description                                               |
S
shawn_he 已提交
346 347
| ---------------------- | --------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|
S
shawn_he 已提交
348

S
shawn_he 已提交
349
**Example**
S
shawn_he 已提交
350

S
shawn_he 已提交
351
```js
S
shawn_he 已提交
352 353 354 355 356 357 358
let promise = call.isEmergencyPhoneNumber("138xxxxxxxx", {slotId: 1});
promise.then(data => {
    console.log(`isEmergencyPhoneNumber success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
    console.error(`isEmergencyPhoneNumber fail, promise: err->${JSON.stringify(err)}`);
});
```
S
shawn_he 已提交
359

S
shawn_he 已提交
360
## call.formatPhoneNumber<sup>7+</sup>
S
shawn_he 已提交
361 362 363

formatPhoneNumber\(phoneNumber: string, callback: AsyncCallback<string\>\): void

S
shawn_he 已提交
364 365 366
Formats a phone number. This API uses an asynchronous callback to return the result.

A formatted phone number is a standard numeric string, for example, 555 0100.
S
shawn_he 已提交
367

S
shawn_he 已提交
368 369
**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
370
**Parameters**
S
shawn_he 已提交
371

S
shawn_he 已提交
372
| Name     | Type                       | Mandatory| Description                                |
S
shawn_he 已提交
373
| ----------- | --------------------------- | ---- | ------------------------------------ |
S
shawn_he 已提交
374 375
| phoneNumber | string                      | Yes  | Phone number.                          |
| callback    | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the result.|
S
shawn_he 已提交
376

S
shawn_he 已提交
377
**Example**
S
shawn_he 已提交
378

S
shawn_he 已提交
379
```js
S
shawn_he 已提交
380 381 382 383
call.formatPhoneNumber("138xxxxxxxx", (err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
384

S
shawn_he 已提交
385
## call.formatPhoneNumber<sup>7+</sup>
S
shawn_he 已提交
386 387 388

formatPhoneNumber\(phoneNumber: string, options: NumberFormatOptions, callback: AsyncCallback<string\>\): void

S
shawn_he 已提交
389
Formats a phone number based on specified formatting options. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
390

S
shawn_he 已提交
391 392
A formatted phone number is a standard numeric string, for example, 555 0100.

S
shawn_he 已提交
393 394
**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
395
**Parameters**
S
shawn_he 已提交
396

S
shawn_he 已提交
397 398 399
| Name     | Type                                        | Mandatory| Description                                |
| ----------- | -------------------------------------------- | ---- | ------------------------------------ |
| phoneNumber | string                                       | Yes  | Phone number.                          |
S
shawn_he 已提交
400
| options     | [NumberFormatOptions](#numberformatoptions7) | Yes  | Number formatting option, for example, country code.              |
S
shawn_he 已提交
401
| callback    | AsyncCallback&lt;string&gt;                  | Yes  | Callback used to return the result.|
S
shawn_he 已提交
402

S
shawn_he 已提交
403
**Example**
S
shawn_he 已提交
404

S
shawn_he 已提交
405
```js
S
shawn_he 已提交
406 407 408 409 410 411
call.formatPhoneNumber("138xxxxxxxx",{
    countryCode: "CN"
}, (err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
412 413


S
shawn_he 已提交
414
## call.formatPhoneNumber<sup>7+</sup>
S
shawn_he 已提交
415 416 417

formatPhoneNumber\(phoneNumber: string, options?: NumberFormatOptions\): Promise<string\>

S
shawn_he 已提交
418
Formats a phone number based on specified formatting options. This API uses a promise to return the result.
S
shawn_he 已提交
419

S
shawn_he 已提交
420 421
A formatted phone number is a standard numeric string, for example, 555 0100.

S
shawn_he 已提交
422 423
**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
424
**Parameters**
S
shawn_he 已提交
425

S
shawn_he 已提交
426 427 428
| Name     | Type                                        | Mandatory| Description                  |
| ----------- | -------------------------------------------- | ---- | ---------------------- |
| phoneNumber | string                                       | Yes  | Phone number.            |
S
shawn_he 已提交
429
| options     | [NumberFormatOptions](#numberformatoptions7) | Yes  | Number formatting option, for example, country code.|
S
shawn_he 已提交
430

S
shawn_he 已提交
431
**Return value**
S
shawn_he 已提交
432

S
shawn_he 已提交
433
| Type                 | Description                                       |
S
shawn_he 已提交
434 435
| --------------------- | ------------------------------------------- |
| Promise&lt;string&gt; | Promise used to return the result.|
S
shawn_he 已提交
436

S
shawn_he 已提交
437
**Example**
S
shawn_he 已提交
438

S
shawn_he 已提交
439
```js
S
shawn_he 已提交
440 441 442 443 444 445 446 447 448
let promise = call.formatPhoneNumber("138xxxxxxxx", {
    countryCode: "CN"
});
promise.then(data => {
    console.log(`formatPhoneNumber success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
    console.error(`formatPhoneNumber fail, promise: err->${JSON.stringify(err)}`);
});
```
S
shawn_he 已提交
449

S
shawn_he 已提交
450
## call.formatPhoneNumberToE164<sup>7+</sup>
S
shawn_he 已提交
451 452 453

formatPhoneNumberToE164\(phoneNumber: string, countryCode: string, callback: AsyncCallback<string\>\): void

S
shawn_he 已提交
454
Converts a phone number into the E.164 format. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
455 456 457

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

S
shawn_he 已提交
458 459
**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
460
**Parameters**
S
shawn_he 已提交
461

S
shawn_he 已提交
462
| Name     | Type                       | Mandatory| Description                                                 |
S
shawn_he 已提交
463
| ----------- | --------------------------- | ---- | ----------------------------------------------------- |
S
shawn_he 已提交
464 465 466
| phoneNumber | string                      | Yes  | Phone number.                                           |
| countryCode | string                      | Yes  | Country code, for example, **CN** (China). All country codes are supported.             |
| callback    | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the result.|
S
shawn_he 已提交
467

S
shawn_he 已提交
468
**Example**
S
shawn_he 已提交
469

S
shawn_he 已提交
470
```js
S
shawn_he 已提交
471 472 473 474 475 476
call.formatPhoneNumberToE164("138xxxxxxxx",{
    countryCode: "CN"
}, (err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
477 478


S
shawn_he 已提交
479
## call.formatPhoneNumberToE164<sup>7+</sup>
S
shawn_he 已提交
480 481 482

formatPhoneNumberToE164\(phoneNumber: string, countryCode: string\): Promise<string\>

S
shawn_he 已提交
483
Converts a phone number into the E.164 format. This API uses a promise to return the result.
S
shawn_he 已提交
484 485 486 487 488

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

All country codes are supported.

S
shawn_he 已提交
489 490
**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
491
**Parameters**
S
shawn_he 已提交
492

S
shawn_he 已提交
493
| Name     | Type  | Mandatory| Description                                    |
S
shawn_he 已提交
494
| ----------- | ------ | ---- | ---------------------------------------- |
S
shawn_he 已提交
495 496
| phoneNumber | string | Yes  | Phone number.                              |
| countryCode | string | Yes  | Country code, for example, **CN** (China). All country codes are supported.|
S
shawn_he 已提交
497

S
shawn_he 已提交
498
**Return value**
S
shawn_he 已提交
499

S
shawn_he 已提交
500
| Type                 | Description                                                        |
S
shawn_he 已提交
501 502
| --------------------- | ------------------------------------------------------------ |
| Promise&lt;string&gt; | Promise used to return the result.|
S
shawn_he 已提交
503

S
shawn_he 已提交
504
**Example**
S
shawn_he 已提交
505

S
shawn_he 已提交
506
```js
S
shawn_he 已提交
507 508 509 510 511 512 513 514 515
let promise = call.formatPhoneNumberToE164("138xxxxxxxx", {
    countryCode: "CN"
});
promise.then(data => {
    console.log(`formatPhoneNumberToE164 success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
    console.error(`formatPhoneNumberToE164 fail, promise: err->${JSON.stringify(err)}`);
});
```
S
shawn_he 已提交
516

S
shawn_he 已提交
517
## DialOptions
S
shawn_he 已提交
518 519

Provides an option for determining whether a call is a video call.
S
shawn_he 已提交
520 521 522

**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
523
| Name| Type   | Mandatory| Description                                                        |
S
shawn_he 已提交
524
| ------ | ------- | ---- | ------------------------------------------------------------ |
S
shawn_he 已提交
525
| extras | boolean | No  | Indication of a video call. <br>- **true**: video call<br>- **false** (default): voice call|
S
shawn_he 已提交
526

S
shawn_he 已提交
527
## CallState
S
shawn_he 已提交
528 529

Enumerates call states.
S
shawn_he 已提交
530

S
shawn_he 已提交
531 532 533
**System capability**: SystemCapability.Telephony.CallManager

| Name              | Value  | Description                                                        |
S
shawn_he 已提交
534
| ------------------ | ---- | ------------------------------------------------------------ |
S
shawn_he 已提交
535 536 537 538
| CALL_STATE_UNKNOWN | -1   | The call status fails to be obtained and is unknown.                        |
| CALL_STATE_IDLE    | 0    | No call is in progress.                                    |
| CALL_STATE_RINGING | 1    | The call is in the ringing or waiting state.                                    |
| CALL_STATE_OFFHOOK | 2    | At least one call is in dialing, active, or on hold, and no new incoming call is ringing or waiting.|
S
shawn_he 已提交
539

S
shawn_he 已提交
540
## EmergencyNumberOptions<sup>7+</sup>
S
shawn_he 已提交
541 542

Provides an option for determining whether a number is an emergency number for the SIM card in the specified slot.
S
shawn_he 已提交
543 544 545

**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
546 547 548
| Name| Type  | Mandatory| Description                                          |
| ------ | ------ | ---- | ---------------------------------------------- |
| slotId | number | No  | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
549

S
shawn_he 已提交
550
## NumberFormatOptions<sup>7+</sup>
S
shawn_he 已提交
551 552

Provides an option for number formatting.
S
shawn_he 已提交
553 554 555

**System capability**: SystemCapability.Telephony.CallManager

S
shawn_he 已提交
556
| Name     | Type  | Mandatory| Description                                                      |
S
shawn_he 已提交
557
| ----------- | ------ | ---- | ---------------------------------------------------------- |
S
shawn_he 已提交
558
| countryCode | string | No  | Country code, for example, **CN** (China). All country codes are supported. The default value is **CN**.|