• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Call
2
3> **NOTE**<br>
4> 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.
5
6
7## Modules to Import
8
9```
10import call from '@ohos.telephony.call';
11```
12
13## call.dial
14
15dial\(phoneNumber: string, callback: AsyncCallback<boolean\>\): void
16
17Initiates a call. This API uses an asynchronous callback to return the execution result.
18
19**Required permission**: ohos.permission.PLACE\_CALL (a system permission)
20
21**System capability**: SystemCapability.Telephony.CallManager
22
23**Parameters**
24
25| Name     | Type                        | Mandatory| Description                                             |
26| ----------- | ---------------------------- | ---- | ------------------------------------------------- |
27| phoneNumber | string                       | Yes  | Phone number.                                       |
28| callback    | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result.<br>- **true**: success<br>- **false**: failure|
29
30**Example**
31
32```
33call.dial("138xxxxxxxx", (err, data) => {
34    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
35});
36```
37
38
39## call.dial
40
41dial\(phoneNumber: string, options: DialOptions, callback: AsyncCallback<boolean\>\): void
42
43Initiates a call. You can set call options as needed. This API uses an asynchronous callback to return the execution result.
44
45**Required permission**: ohos.permission.PLACE\_CALL (a system permission)
46
47**System capability**: SystemCapability.Telephony.CallManager
48
49**Parameters**
50
51| Name     | Type                        | Mandatory| Description                                             |
52| ----------- | ---------------------------- | ---- | ------------------------------------------------- |
53| phoneNumber | string                       | Yes  | Phone number.                                       |
54| options     | DialOptions                  | Yes  | Call options defined in [DialOptions](#dialoptions).      |
55| callback    | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result.<br>- **true**: success<br>- **false**: failure|
56
57**Example**
58
59```
60call.dial("138xxxxxxxx", {
61    extras: false
62}, (err, data) => {
63    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
64});
65```
66
67
68## call.dial
69
70dial\(phoneNumber: string, options?: DialOptions\): Promise<boolean\>
71
72Initiates a call. You can set call options as needed. This API uses a promise to return the execution result.
73
74**Required permission**: ohos.permission.PLACE\_CALL (a system permission)
75
76**System capability**: SystemCapability.Telephony.CallManager
77
78**Parameters**
79
80| Name     | Type       | Mandatory| Description                                       |
81| ----------- | ----------- | ---- | ------------------------------------------- |
82| phoneNumber | string      | Yes  | Phone number.                                 |
83| options     | DialOptions | Yes  | Call options defined in [DialOptions](#dialoptions).|
84
85**Return Value**
86
87| Type                  | Description                             |
88| ---------------------- | --------------------------------- |
89| Promise&lt;boolean&gt; | Promise used to return the result.|
90
91**Example**
92
93```
94let promise = call.dial("138xxxxxxxx", {
95    extras: false
96});
97promise.then(data => {
98    console.log(`dial success, promise: data->${JSON.stringify(data)}`);
99}).catch(err => {
100    console.error(`dial fail, promise: err->${JSON.stringify(err)}`);
101});
102```
103
104## call.makeCall<sup>7+</sup>
105
106makeCall(phoneNumber: string, callback: AsyncCallback\<void\>): void
107
108Launches the call screen and displays the dialed number. This API uses an asynchronous callback to return the result.
109
110This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
111
112**System capability**: SystemCapability.Applications.Contacts
113
114**Parameters**
115
116| Name     | Type                     | Mandatory| Description                                      |
117| ----------- | ------------------------- | ---- | ------------------------------------------ |
118| phoneNumber | string                    | Yes  | Phone number.                                |
119| callback    | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.|
120
121**Example**
122
123```
124call.makeCall("138xxxxxxxx", err => {
125    console.log(`makeCall callback: err->${JSON.stringify(err)}`);
126});
127```
128
129
130## call.makeCall<sup>7+</sup>
131
132makeCall(phoneNumber: string): Promise\<void\>
133
134Launches the call screen and displays the dialed number. This API uses a promise to return the result.
135
136This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
137
138**System capability**: SystemCapability.Applications.Contacts
139
140**Parameters**
141
142| Name     | Type  | Mandatory| Description      |
143| ----------- | ------ | ---- | ---------- |
144| phoneNumber | string | Yes  | Phone number.|
145
146**Return Value**
147
148| Type               | Description                             |
149| ------------------- | --------------------------------- |
150| Promise&lt;void&gt; | Promise used to return the result.|
151
152**Example**
153
154```
155let promise = call.makeCall("138xxxxxxxx");
156promise.then(() => {
157    console.log(`makeCall success`);
158}).catch(err => {
159    console.error(`makeCall fail, promise: err->${JSON.stringify(err)}`);
160});
161```
162
163## call.hasCall
164
165hasCall\(callback: AsyncCallback<boolean\>\): void
166
167Checks whether a call is in progress. This API uses an asynchronous callback to return the result.
168
169**System capability**: SystemCapability.Telephony.CallManager
170
171**Parameters**
172
173| Name  | Type                        | Mandatory| Description                                                        |
174| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
175| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result.<br>- **true**: A call is in progress.<br>- **false**: No call is in progress.|
176
177**Example**
178
179```
180call.hasCall((err, data) => {
181    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
182});
183```
184
185
186## call.hasCall
187
188hasCall\(\): Promise<boolean\>
189
190Checks whether a call is in progress. This API uses a promise to return the result.
191
192**System capability**: SystemCapability.Telephony.CallManager
193
194**Return Value**
195
196| Type                  | Description                                   |
197| ---------------------- | --------------------------------------- |
198| Promise&lt;boolean&gt; | Promise used to return the result.|
199
200**Example**
201
202```
203let promise = call.hasCall();
204promise.then(data => {
205    console.log(`hasCall success, promise: data->${JSON.stringify(data)}`);
206}).catch(err => {
207    console.error(`hasCall fail, promise: err->${JSON.stringify(err)}`);
208});
209```
210
211
212## call.getCallState
213
214getCallState\(callback: AsyncCallback<CallState\>\): void
215
216Obtains the call status. This API uses an asynchronous callback to return the result.
217
218**System capability**: SystemCapability.Telephony.CallManager
219
220**Parameters**
221
222| Name  | Type                                        | Mandatory| Description                                |
223| -------- | -------------------------------------------- | ---- | ------------------------------------ |
224| callback | AsyncCallback&lt;[CallState](#callstate)&gt; | Yes  | Callback used to return the result.|
225
226**Example**
227
228```
229call.getCallState((err, data) => {
230    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
231});
232```
233
234
235## call.getCallState
236
237getCallState\(\): Promise<CallState\>
238
239Obtains the call status. This API uses a promise to return the result.
240
241**System capability**: SystemCapability.Telephony.CallManager
242
243**Return Value**
244
245| Type                                  | Description                                     |
246| -------------------------------------- | ----------------------------------------- |
247| Promise&lt;[CallState](#callstate)&gt; | Promise used to return the result.|
248
249**Example**
250
251```
252let promise = call.getCallState();
253promise.then(data => {
254    console.log(`getCallState success, promise: data->${JSON.stringify(data)}`);
255}).catch(err => {
256    console.error(`getCallState fail, promise: err->${JSON.stringify(err)}`);
257});
258```
259
260## call.hasVoiceCapability<sup>7+</sup>
261
262hasVoiceCapability(): boolean
263
264Checks whether a device supports voice calls. This API works in synchronous mode.
265
266**System capability**: SystemCapability.Telephony.CallManager
267
268**Return Value**
269
270| Type   | Description                                                        |
271| ------- | ------------------------------------------------------------ |
272| boolean | - **true**: The device supports voice calls.<br>- **false**: The device does not support voice calls.|
273
274```
275let result = call.hasVoiceCapability();
276console.log(`hasVoiceCapability: ${JSON.stringify(result)}`);
277```
278
279## call.isEmergencyPhoneNumber<sup>7+</sup>
280
281isEmergencyPhoneNumber\(phoneNumber: string, callback: AsyncCallback<boolean\>\): void
282
283Checks whether the call number of the SIM card in the specified slot is an emergency number. This API uses an asynchronous callback to return the result.
284
285**System capability**: SystemCapability.Telephony.CallManager
286
287**Parameters**
288
289| Name     | Type                        | Mandatory| Description                                                        |
290| ----------- | ---------------------------- | ---- | ------------------------------------------------------------ |
291| phoneNumber | string                       | Yes  | Phone number.                                                  |
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.|
293
294**Example**
295
296```
297call.isEmergencyPhoneNumber("138xxxxxxxx", (err, data) => {
298    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
299});
300```
301
302
303## call.isEmergencyPhoneNumber<sup>7+</sup>
304
305isEmergencyPhoneNumber\(phoneNumber: string, options: EmergencyNumberOptions, callback: AsyncCallback<boolean\>\): void
306
307Checks whether the call number of the SIM card in the specified slot is an emergency number. This API uses an asynchronous callback to return the result.
308
309**System capability**: SystemCapability.Telephony.CallManager
310
311**Parameters**
312
313| Name     | Type                        | Mandatory| Description                                                        |
314| ----------- | ---------------------------- | ---- | ------------------------------------------------------------ |
315| phoneNumber | string                       | Yes  | Phone number.                                                  |
316| options     | EmergencyNumberOptions       | Yes  | Emergency number options defined in [EmergencyNumberOptions](#emergencynumberoptions7).|
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.|
318
319**Example**
320
321```
322call.isEmergencyPhoneNumber("112", {slotId: 1}, (err, value) => {
323    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
324});
325```
326
327
328## call.isEmergencyPhoneNumber<sup>7+</sup>
329
330isEmergencyPhoneNumber\(phoneNumber: string, options?: EmergencyNumberOptions\): Promise<boolean\>
331
332Checks whether the call number of the SIM card in the specified slot is an emergency number. This API uses a promise to return the result.
333
334**System capability**: SystemCapability.Telephony.CallManager
335
336**Parameters**
337
338| Name     | Type                  | Mandatory| Description                                                        |
339| ----------- | ---------------------- | ---- | ------------------------------------------------------------ |
340| phoneNumber | string                 | Yes  | Phone number.                                                  |
341| options     | EmergencyNumberOptions | Yes  | Emergency number options defined in [EmergencyNumberOptions](#emergencynumberoptions7).|
342
343**Return Value**
344
345| Type                  | Description                                               |
346| ---------------------- | --------------------------------------------------- |
347| Promise&lt;boolean&gt; | Promise used to return the result.|
348
349**Example**
350
351```
352let promise = call.isEmergencyPhoneNumber("138xxxxxxxx", {slotId: 1});
353promise.then(data => {
354    console.log(`isEmergencyPhoneNumber success, promise: data->${JSON.stringify(data)}`);
355}).catch(err => {
356    console.error(`isEmergencyPhoneNumber fail, promise: err->${JSON.stringify(err)}`);
357});
358```
359
360## call.formatPhoneNumber<sup>7+</sup>
361
362formatPhoneNumber\(phoneNumber: string, callback: AsyncCallback<string\>\): void
363
364Formats a phone number based on the specified ISO country code. This API uses an asynchronous callback to return the result.
365
366**System capability**: SystemCapability.Telephony.CallManager
367
368**Parameters**
369
370| Name     | Type                       | Mandatory| Description                                |
371| ----------- | --------------------------- | ---- | ------------------------------------ |
372| phoneNumber | string                      | Yes  | Phone number.                          |
373| callback    | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the result.|
374
375**Example**
376
377```
378call.formatPhoneNumber("138xxxxxxxx", (err, data) => {
379    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
380});
381```
382
383
384## call.formatPhoneNumber<sup>7+</sup>
385
386formatPhoneNumber\(phoneNumber: string, options: NumberFormatOptions, callback: AsyncCallback<string\>\): void
387
388Formats a phone number based on specified formatting options. This API uses an asynchronous callback to return the result.
389
390**System capability**: SystemCapability.Telephony.CallManager
391
392**Parameters**
393
394| Name     | Type                       | Mandatory| Description                                                        |
395| ----------- | --------------------------- | ---- | ------------------------------------------------------------ |
396| phoneNumber | string                      | Yes  | Phone number.                                                  |
397| options     | NumberFormatOptions         | Yes  | Number formatting options defined in [NumberFormatOptions](#numberformatoptions7).|
398| callback    | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the result.                        |
399
400**Example**
401
402```
403call.formatPhoneNumber("138xxxxxxxx",{
404    countryCode: "CN"
405}, (err, data) => {
406    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
407});
408```
409
410
411## call.formatPhoneNumber<sup>7+</sup>
412
413formatPhoneNumber\(phoneNumber: string, options?: NumberFormatOptions\): Promise<string\>
414
415Formats a phone number based on specified formatting options. This API uses a promise to return the result.
416
417**System capability**: SystemCapability.Telephony.CallManager
418
419**Parameters**
420
421| Name     | Type               | Mandatory| Description                                                        |
422| ----------- | ------------------- | ---- | ------------------------------------------------------------ |
423| phoneNumber | string              | Yes  | Phone number.                                                  |
424| options     | NumberFormatOptions | Yes  | Number formatting options defined in [NumberFormatOptions](#numberformatoptions7).|
425
426**Return Value**
427
428| Type                 | Description                                       |
429| --------------------- | ------------------------------------------- |
430| Promise&lt;string&gt; | Promise used to return the result.|
431
432**Example**
433
434```
435let promise = call.formatPhoneNumber("138xxxxxxxx", {
436    countryCode: "CN"
437});
438promise.then(data => {
439    console.log(`formatPhoneNumber success, promise: data->${JSON.stringify(data)}`);
440}).catch(err => {
441    console.error(`formatPhoneNumber fail, promise: err->${JSON.stringify(err)}`);
442});
443```
444
445## call.formatPhoneNumberToE164<sup>7+</sup>
446
447formatPhoneNumberToE164\(phoneNumber: string, countryCode: string, callback: AsyncCallback<string\>\): void
448
449Converts a phone number into the E.164 format. This API uses an asynchronous callback to return the result.
450
451The 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.
452
453All country codes are supported.
454
455**System capability**: SystemCapability.Telephony.CallManager
456
457**Parameters**
458
459| Name     | Type                       | Mandatory| Description                                                 |
460| ----------- | --------------------------- | ---- | ----------------------------------------------------- |
461| phoneNumber | string                      | Yes  | Phone number.                                           |
462| countryCode | string                      | Yes  | Country code, for example, **CN** (China). All country codes are supported.             |
463| callback    | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the result.|
464
465**Example**
466
467```
468call.formatPhoneNumberToE164("138xxxxxxxx",{
469    countryCode: "CN"
470}, (err, data) => {
471    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
472});
473```
474
475
476## call.formatPhoneNumberToE164<sup>7+</sup>
477
478formatPhoneNumberToE164\(phoneNumber: string, countryCode: string\): Promise<string\>
479
480Converts a phone number into the E.164 format. This API uses a promise to return the result.
481
482The 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.
483
484All country codes are supported.
485
486**System capability**: SystemCapability.Telephony.CallManager
487
488**Parameters**
489
490| Name     | Type  | Mandatory| Description                                    |
491| ----------- | ------ | ---- | ---------------------------------------- |
492| phoneNumber | string | Yes  | Phone number.                              |
493| countryCode | string | Yes  | Country code, for example, **CN** (China). All country codes are supported.|
494
495**Return Value**
496
497| Type                 | Description                                                        |
498| --------------------- | ------------------------------------------------------------ |
499| Promise&lt;string&gt; | Promise used to return the result.|
500
501**Example**
502
503```
504let promise = call.formatPhoneNumberToE164("138xxxxxxxx", {
505    countryCode: "CN"
506});
507promise.then(data => {
508    console.log(`formatPhoneNumberToE164 success, promise: data->${JSON.stringify(data)}`);
509}).catch(err => {
510    console.error(`formatPhoneNumberToE164 fail, promise: err->${JSON.stringify(err)}`);
511});
512```
513
514## DialOptions
515
516Provides an option for determining whether a call is a video call.
517
518**System capability**: SystemCapability.Telephony.CallManager
519
520| Name| Type   | Mandatory| Description                                                        |
521| ------ | ------- | ---- | ------------------------------------------------------------ |
522| extras | boolean | No  | Indication of a video call. <br>- **true**: video call<br>- **false** (default): voice call|
523
524## CallState
525
526Enumerates call states.
527
528**System capability**: SystemCapability.Telephony.CallManager
529
530| Name              | Value  | Description                                                        |
531| ------------------ | ---- | ------------------------------------------------------------ |
532| CALL_STATE_UNKNOWN | -1   | The call status fails to be obtained and is unknown.                        |
533| CALL_STATE_IDLE    | 0    | No call is in progress.                                    |
534| CALL_STATE_RINGING | 1    | The call is in the ringing or waiting state.                                    |
535| CALL_STATE_OFFHOOK | 2    | At least one call is in dialing, active, or on hold, and no new incoming call is ringing or waiting.|
536
537## EmergencyNumberOptions<sup>7+</sup>
538
539Provides an option for determining whether a number is an emergency number for the SIM card in the specified slot.
540
541**System capability**: SystemCapability.Telephony.CallManager
542
543| Name| Type  | Mandatory| Description                                      |
544| ------ | ------ | ---- | ------------------------------------------ |
545| slotId | number | No  | Card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2|
546
547## NumberFormatOptions<sup>7+</sup>
548
549Provides an option for number formatting.
550
551**System capability**: SystemCapability.Telephony.CallManager
552
553| Name     | Type  | Mandatory| Description                                                      |
554| ----------- | ------ | ---- | ---------------------------------------------------------- |
555| countryCode | string | No  | Country code, for example, **CN** (China). All country codes are supported. The default value is **CN**.|
556