@ohos.telephony.call (Call)

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 call status changes, use observer.on('callStateChange').

NOTE

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.

Modules to Import

import call from '@ohos.telephony.call';

call.dial(deprecated)

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

Initiates a call. 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. The substitute API is available only for system applications.

Required permissions: ohos.permission.PLACE_CALL (available only for system applications)

System capability: SystemCapability.Telephony.CallManager

Parameters

Name Type Mandatory Description
phoneNumber string Yes Phone number.
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.

Example

import { BusinessError } from '@ohos.base';

call.dial("138xxxxxxxx", (err: BusinessError, data: boolean) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

call.dial(deprecated)

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

Initiates a call. You can set call options as needed. 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. The substitute API is available only for system applications.

Required permissions: ohos.permission.PLACE_CALL (available only for system applications)

System capability: SystemCapability.Telephony.CallManager

Parameters

Name Type Mandatory Description
phoneNumber string Yes Phone number.
options DialOptions Yes Call option, which indicates whether the call is a voice call or video call.
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.

Example

import { BusinessError } from '@ohos.base';

let dialOptions: call.DialOptions = {
    extras: false
}
call.dial("138xxxxxxxx", dialOptions, (err: BusinessError, data: boolean) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

call.dial(deprecated)

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

Initiates a call. You can set call options as needed. This API uses a promise to return the result.

NOTE

This API is supported since API version 6 and deprecated since API version 9. The substitute API is available only for system applications.

Required permissions: ohos.permission.PLACE_CALL (available only for system applications)

System capability: SystemCapability.Telephony.CallManager

Parameters

Name Type Mandatory Description
phoneNumber string Yes Phone number.
options DialOptions No Call option, which indicates whether the call is a voice call or video call.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true indicates that the operation is successful, and the value false indicates the opposite.

Example

import { BusinessError } from '@ohos.base';

let dialOptions: call.DialOptions = {
    extras: false
}
call.dial("138xxxxxxxx", dialOptions).then((data: boolean) => {
    console.log(`dial success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`dial fail, promise: err->${JSON.stringify(err)}`);
});

call.makeCall7+

makeCall(phoneNumber: string, callback: AsyncCallback<void>): void

Launches the call screen and displays the dialed number. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Applications.Contacts

Parameters

Name Type Mandatory Description
phoneNumber string Yes Phone number.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see ohos.telephony (Telephony) Error Codes and Universal Error Codes.

ID Error Message
401 Parameter error.
8300001 Invalid parameter value.
8300002 Operation failed. Cannot connect to service.
8300003 System internal error.
8300999 Unknown error code.

Example

import { BusinessError } from '@ohos.base';

call.makeCall("138xxxxxxxx", (err: BusinessError) => {
    if (err) {
        console.error(`makeCall fail, err->${JSON.stringify(err)}`);
    } else {
        console.log(`makeCall success`);
    }
});

call.makeCall7+

makeCall(phoneNumber: string): Promise<void>

Launches the call screen and displays the dialed number. This API uses a promise to return the result.

System capability: SystemCapability.Applications.Contacts

Parameters

Name Type Mandatory Description
phoneNumber string Yes Phone number.

Return value

Type Description
Promise<void> Promise used to return the result.

Error codes

For details about the error codes, see ohos.telephony (Telephony) Error Codes and Universal Error Codes.

ID Error Message
401 Parameter error.
8300001 Invalid parameter value.
8300002 Operation failed. Cannot connect to service.
8300003 System internal error.
8300999 Unknown error code.

Example

import { BusinessError } from '@ohos.base';

call.makeCall("138xxxxxxxx").then(() => {
    console.log(`makeCall success`);
}).catch((err: BusinessError) => {
    console.error(`makeCall fail, promise: err->${JSON.stringify(err)}`);
});

call.hasCall

hasCall(callback: AsyncCallback<boolean>): void

Checks whether a call is in progress. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CallManager

Parameters

Name Type Mandatory Description
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.

Example

import { BusinessError } from '@ohos.base';

call.hasCall((err: BusinessError, data: boolean) => {
    if (err) {
        console.error(`hasCall fail, err->${JSON.stringify(err)}`);
    } else {
        console.log(`hasCall success, data->${JSON.stringify(data)}`);
    }
});

call.hasCall

hasCall(): Promise<boolean>

Checks whether a call is in progress. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CallManager

Return value

Type Description
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.

Example

import { BusinessError } from '@ohos.base';

call.hasCall().then(() => {
    console.log(`hasCall success`);
}).catch((err: BusinessError) => {
    console.error(`hasCall fail, promise: err->${JSON.stringify(err)}`);
});

call.hasCallSync10+

hasCallSync(): boolean

Checks whether a call is in progress.

System capability: SystemCapability.Telephony.CallManager

Return value

Type Description
boolean Promise used to return the result. The value true indicates that a call is in progress, and the value false indicates the opposite.

Example

let hasCall: boolean = call.hasCallSync();
console.log(`hasCallSync success, has call is ` + hasCall);

call.getCallState

getCallState(callback: AsyncCallback<CallState>): void

Obtains the call status. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CallManager

Parameters

Name Type Mandatory Description
callback AsyncCallback<CallState> Yes Callback used to return the result.

Example

import { BusinessError } from '@ohos.base';

call.getCallState((err: BusinessError, data: call.CallState) => {
    if (err) {
        console.error(`getCallState fail, err->${JSON.stringify(err)}`);
    } else {
        console.log(`getCallState success, data->${JSON.stringify(data)}`);
    }
});

call.getCallState

getCallState(): Promise<CallState>

Obtains the call status. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CallManager

Return value

Type Description
Promise<CallState> Promise used to return the result.

Example

import { BusinessError } from '@ohos.base';

call.getCallState().then((data: call.CallState) => {
    console.log(`getCallState success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getCallState fail, promise: err->${JSON.stringify(err)}`);
});

call.getCallStateSync10+

getCallStateSync(): CallState

Obtains the call status.

System capability: SystemCapability.Telephony.CallManager

Return value

Type Description
CallState Promise used to return the result.

Example

let callState: call.CallState = call.getCallStateSync();
console.log(`the call state is:` + callState);

call.hasVoiceCapability7+

hasVoiceCapability(): boolean

Checks whether a device supports voice calls.

System capability: SystemCapability.Telephony.CallManager

Return value

Type Description
boolean Result indicating whether the device supports voice calls. The value true indicates yes, and the value false indicates no.
let result: boolean = call.hasVoiceCapability();
console.log(`hasVoiceCapability: ${JSON.stringify(result)}`);

call.isEmergencyPhoneNumber7+

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

Checks whether the called number is an emergency number. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CallManager

Parameters

Name Type Mandatory Description
phoneNumber string Yes Phone number.
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.

Error codes

For details about the error codes, see ohos.telephony (Telephony) Error Codes and Universal Error Codes.

ID Error Message
401 Parameter error.
8300001 Invalid parameter value.
8300002 Operation failed. Cannot connect to service.
8300003 System internal error.
8300999 Unknown error code.

Example

import { BusinessError } from '@ohos.base';

call.isEmergencyPhoneNumber("138xxxxxxxx", (err: BusinessError, data: boolean) => {
    if (err) {
        console.error(`isEmergencyPhoneNumber fail, err->${JSON.stringify(err)}`);
    } else {
        console.log(`isEmergencyPhoneNumber success, data->${JSON.stringify(data)}`);
    }
});

call.isEmergencyPhoneNumber7+

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

Checks whether the called number is an emergency number based on the phone number. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CallManager

Parameters

Name Type Mandatory Description
phoneNumber string Yes Phone number.
options EmergencyNumberOptions Yes Emergency number options.
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.

Error codes

For details about the error codes, see ohos.telephony (Telephony) Error Codes and Universal Error Codes.

ID Error Message
401 Parameter error.
8300001 Invalid parameter value.
8300002 Operation failed. Cannot connect to service.
8300003 System internal error.
8300999 Unknown error code.

Example

import { BusinessError } from '@ohos.base';

let options: call.EmergencyNumberOptions = {slotId: 1}
call.isEmergencyPhoneNumber("112", options, (err: BusinessError, data: boolean) => {
    if (err) {
        console.error(`isEmergencyPhoneNumber fail, err->${JSON.stringify(err)}`);
    } else {
        console.log(`isEmergencyPhoneNumber success, data->${JSON.stringify(data)}`);
    }
});

call.isEmergencyPhoneNumber7+

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

Checks whether the called number is an emergency number based on the phone number. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CallManager

Parameters

Name Type Mandatory Description
phoneNumber string Yes Phone number.
options EmergencyNumberOptions No Emergency number options.

Return value

Type Description
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.

Error codes

For details about the error codes, see ohos.telephony (Telephony) Error Codes and Universal Error Codes.

ID Error Message
401 Parameter error.
8300001 Invalid parameter value.
8300002 Operation failed. Cannot connect to service.
8300003 System internal error.
8300999 Unknown error code.

Example

import { BusinessError } from '@ohos.base';

let options: call.EmergencyNumberOptions = {slotId: 1}
call.isEmergencyPhoneNumber("138xxxxxxxx", options).then((data: boolean) => {
    console.log(`isEmergencyPhoneNumber success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`isEmergencyPhoneNumber fail, promise: err->${JSON.stringify(err)}`);
});

call.formatPhoneNumber7+

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

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.

System capability: SystemCapability.Telephony.CallManager

Parameters

Name Type Mandatory Description
phoneNumber string Yes Phone number.
callback AsyncCallback<string> Yes Callback used to return the result.

Error codes

For details about the error codes, see ohos.telephony (Telephony) Error Codes and Universal Error Codes.

ID Error Message
401 Parameter error.
8300001 Invalid parameter value.
8300002 Operation failed. Cannot connect to service.
8300003 System internal error.
8300999 Unknown error code.

Example

import { BusinessError } from '@ohos.base';

call.formatPhoneNumber("138xxxxxxxx", (err: BusinessError, data: string) => {
    if (err) {
        console.error(`formatPhoneNumber fail, err->${JSON.stringify(err)}`);
    } else {
        console.log(`formatPhoneNumber success, data->${JSON.stringify(data)}`);
    }
});

call.formatPhoneNumber7+

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

Formats a phone number based on specified formatting options. This API uses an asynchronous callback to return the result.

A formatted phone number is a standard numeric string, for example, 555 0100.

System capability: SystemCapability.Telephony.CallManager

Parameters

Name Type Mandatory Description
phoneNumber string Yes Phone number.
options NumberFormatOptions Yes Number formatting options, for example, country code.
callback AsyncCallback<string> Yes Callback used to return the result.

Error codes

For details about the error codes, see ohos.telephony (Telephony) Error Codes and Universal Error Codes.

ID Error Message
401 Parameter error.
8300001 Invalid parameter value.
8300002 Operation failed. Cannot connect to service.
8300003 System internal error.
8300999 Unknown error code.

Example

import { BusinessError } from '@ohos.base';

let options: call.NumberFormatOptions = {
    countryCode: "CN"
}
call.formatPhoneNumber("138xxxxxxxx", options, (err: BusinessError, data: string) => {
    if (err) {
        console.error(`formatPhoneNumber fail, err->${JSON.stringify(err)}`);
    } else {
        console.log(`formatPhoneNumber success, data->${JSON.stringify(data)}`);
    }
});

call.formatPhoneNumber7+

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

Formats a phone number based on specified formatting options. This API uses a promise to return the result.

A formatted phone number is a standard numeric string, for example, 555 0100.

System capability: SystemCapability.Telephony.CallManager

Parameters

Name Type Mandatory Description
phoneNumber string Yes Phone number.
options NumberFormatOptions No Number formatting options, for example, country code.

Return value

Type Description
Promise<string> Promise used to return the result.

Error codes

For details about the error codes, see ohos.telephony (Telephony) Error Codes and Universal Error Codes.

ID Error Message
401 Parameter error.
8300001 Invalid parameter value.
8300002 Operation failed. Cannot connect to service.
8300003 System internal error.
8300999 Unknown error code.

Example

import { BusinessError } from '@ohos.base';

let options: call.NumberFormatOptions = {
    countryCode: "CN"
}
call.formatPhoneNumber("138xxxxxxxx", options).then((data: string) => {
    console.log(`formatPhoneNumber success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`formatPhoneNumber fail, promise: err->${JSON.stringify(err)}`);
});

call.formatPhoneNumberToE1647+

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

Converts a phone number into the E.164 format. This API uses an asynchronous callback to return the result.

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.

System capability: SystemCapability.Telephony.CallManager

Parameters

Name Type Mandatory Description
phoneNumber string Yes Phone number.
countryCode string Yes Country code, for example, CN (China). All country codes are supported.
callback AsyncCallback<string> Yes Callback used to return the result.

Error codes

For details about the error codes, see ohos.telephony (Telephony) Error Codes and Universal Error Codes.

ID Error Message
401 Parameter error.
8300001 Invalid parameter value.
8300002 Operation failed. Cannot connect to service.
8300003 System internal error.
8300999 Unknown error code.

Example

import { BusinessError } from '@ohos.base';

call.formatPhoneNumberToE164("138xxxxxxxx", "CN", (err: BusinessError, data: string) => {
    if (err) {
        console.error(`formatPhoneNumberToE164 fail, err->${JSON.stringify(err)}`);
    } else {
        console.log(`formatPhoneNumberToE164 success, data->${JSON.stringify(data)}`);
    }
});

call.formatPhoneNumberToE1647+

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

Converts a phone number into the E.164 format. This API uses a promise to return the result.

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.

System capability: SystemCapability.Telephony.CallManager

Parameters

Name Type Mandatory Description
phoneNumber string Yes Phone number.
countryCode string Yes Country code, for example, CN (China). All country codes are supported.

Return value

Type Description
Promise<string> Promise used to return the result.

Error codes

For details about the error codes, see ohos.telephony (Telephony) Error Codes and Universal Error Codes.

ID Error Message
401 Parameter error.
8300001 Invalid parameter value.
8300002 Operation failed. Cannot connect to service.
8300003 System internal error.
8300999 Unknown error code.

Example

import { BusinessError } from '@ohos.base';

call.formatPhoneNumberToE164("138xxxxxxxx", "CN").then((data: string) => {
    console.log(`formatPhoneNumberToE164 success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`formatPhoneNumberToE164 fail, promise: err->${JSON.stringify(err)}`);
});

DialOptions

Provides an option for determining whether a call is a video call.

System capability: SystemCapability.Telephony.CallManager

Name Type Mandatory Description
extras boolean No Whether the call is a video call.
- true: video call
- false (default): voice call

CallState

Enumerates call states.

System capability: SystemCapability.Telephony.CallManager

Name Value Description
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.

EmergencyNumberOptions7+

Provides an option for determining whether a number is an emergency number for the SIM card in the specified slot.

System capability: SystemCapability.Telephony.CallManager

Name Type Mandatory Description
slotId number No Card slot ID.
- 0: card slot 1
- 1: card slot 2

NumberFormatOptions7+

Provides an option for number formatting.

System capability: SystemCapability.Telephony.CallManager

Name Type Mandatory Description
countryCode string No Country code, for example, CN (China). All country codes are supported. The default value is CN.