1# Call Service Development
2
3## Scenario Description
4
5You can implement the call service in either of the following ways:
6<!--Del-->
7- For a system application, use the **dialCall** API to make a voice or video call. The call will be displayed on the application page.
8<!--DelEnd-->
9- For a third-party application, use the **makeCall** API to start the system call application. Users can then make calls as needed.
10
11## Basic Concepts
12
13- Call status code
14  A code used to report the current call status to the application, so that the application can then take appropriate logic processing. For example, if there is no ongoing call, the application allows you to make a new call.
15
16  | Name              | Value  | Description                                                        |
17  | ------------------ | ---- | ------------------------------------------------------------ |
18  | CALL_STATE_UNKNOWN | -1   | The call status fails to be obtained and is unknown.                        |
19  | CALL_STATE_IDLE    | 0    | No call is in progress.                                    |
20  | CALL_STATE_RINGING | 1    | The call is in the ringing or waiting state.                                    |
21  | CALL_STATE_OFFHOOK | 2    | At least one call is in dialing, active, or on hold, and no new incoming call is ringing or waiting.|
22
23## Constraints
24
251. The call service is available only on standard-system devices.
262. An available SIM card must be present on the device.
27
28
29## Available APIs
30
31> **NOTE**
32> To maximize the application running efficiency, most API calls are called asynchronously in callback or promise mode. The following code examples use the callback mode. For details about the APIs, see [API Reference](../reference/apis-telephony-kit/js-apis-call.md).
33
34|                                  Name                                            | Description                                                        |
35| ----------------------------------------------------------------------------------- | ------------------------------------------------------------ |
36| hasVoiceCapability(): boolean;                                                      | Checks whether the voice function is available.                                       |
37|<!--DelRow--> dialCall(phoneNumber: string, callback: AsyncCallback&lt;void&gt;): void;                 | Makes a call. This is a system API.                                     |
38| makeCall(phoneNumber: string, callback: AsyncCallback&lt;void&gt;): void;                 | Redirects to the dial screen and displays the called number.                                 |
39
40The **observer** module provides the functions of subscribing to and unsubscribing from the call service status. For details about the APIs, see [API Reference](../reference/apis-telephony-kit/js-apis-observer.md).
41
42| Name                                                      | Description              |
43| ------------------------------------------------------------ | ------------------ |
44| on(type: 'callStateChange', options: { slotId: number }, callback: Callback<{ state: CallState, number: string }>): void; | Listens to call status changes.|
45
46## How to Develop
47
48<!--Del-->
49### Making a Call by Using the dialCall API (Only for System Applications)
50
511. Declare the required permission: **ohos.permission.PLACE_CALL**.
52This permission is of the **system\_basic** level. Before applying for the permission, ensure that the [basic principles for permission management](../security/AccessToken/app-permission-mgmt-overview.md#basic-principles-for-using-permissions) are met. Then, declare the requried permission by referring to [Requesting Application Permissions](../security/AccessToken/determine-application-mode.md#requesting-permissions-for-system_basic-applications).
531. Import the **call** and **observer** modules.
542. Invoke the **hasVoiceCapability** API to check whether the device supports the voice call function.
553. Invoke the **dialCall** API to make a call.
564. (Optional) Register the observer for call service status changes.
57   ```ts
58    // Import the required modules.
59    import { call, observer } from '@kit.TelephonyKit';
60    import { BusinessError } from '@kit.BasicServicesKit';
61
62    // Check whether the voice call function is supported.
63    let isSupport = call.hasVoiceCapability();
64    if (isSupport) {
65        // If the device supports the voice call function, call the following API to make a call.
66        call.dialCall("13xxxx", (err: BusinessError) => {
67            console.log(`callback: dial call err->${JSON.stringify(err)}`);
68        })
69
70        // (Optional) Register the observer for call service status changes.
71        class SlotId {slotId: number = 0}
72        class CallStateCallback {
73            state: call.CallState = call.CallState.CALL_STATE_UNKNOWN;
74            number: string = "";
75        }
76        let slotId: SlotId = {slotId: 0}
77        observer.on("callStateChange", slotId, (data: CallStateCallback) => {
78            console.log("call state change, data is:" + JSON.stringify(data));
79        });
80    }
81   ```
82<!--DelEnd-->
83### Making a Call by Using the makeCall API
84
851. Import the **call** and **observer** modules.
862. Invoke the **hasVoiceCapability** API to check whether the device supports the voice call function.
873. Call the **makeCall** API to launch the dial screen and display the dialed number.
884. (Optional) Register the observer for call service status changes.
89
90   ```ts
91    // Import the required modules.
92    import { call, observer } from '@kit.TelephonyKit';
93    import { BusinessError } from '@kit.BasicServicesKit';
94
95    // Check whether the voice call function is supported.
96    let isSupport = call.hasVoiceCapability();
97    if (isSupport) {
98        // If the voice call function is supported, the user will be redirected to the dial screen and the dialed number is displayed.
99        call.makeCall("13xxxx", (err: BusinessError) => {
100            if (!err) {
101                console.log("make call success.");
102            } else {
103                console.log("make call fail, err is:" + JSON.stringify(err));
104            }
105        });
106        // (Optional) Register the observer for call service status changes.
107        class SlotId {slotId: number = 0}
108        class CallStateCallback {
109            state: call.CallState = call.CallState.CALL_STATE_UNKNOWN;
110            number: string = "";
111        }
112        let slotId: SlotId = {slotId: 0}
113        observer.on("callStateChange", slotId, (data: CallStateCallback) => {
114            console.log("call state change, data is:" + JSON.stringify(data));
115        });
116    }
117   ```
118