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').
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.
dial(phoneNumber: string, callback: AsyncCallback<boolean>): void
Initiates a call. This API uses an asynchronous callback to return the result.
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 '@kit.BasicServicesKit';
call.dial("138xxxxxxxx", (err: BusinessError, data: boolean) => {
console.info(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); 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.
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 '@kit.BasicServicesKit';
let dialOptions: call.DialOptions = {
extras: false
};
call.dial("138xxxxxxxx", dialOptions, (err: BusinessError, data: boolean) => {
console.info(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); 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.
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. The default value is voice 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 '@kit.BasicServicesKit';
let dialOptions: call.DialOptions = {
extras: false
};
call.dial("138xxxxxxxx", dialOptions).then((data: boolean) => {
console.info(`dial success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`dial fail, promise: err->Code${err.code}, message:${err.message}`);
}); makeCall(phoneNumber: string, callback: AsyncCallback<void>): void
Launches the call screen and displays the dialed number. This API can be called only in UIAbility. This API uses an asynchronous callback to return the result.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.Applications.Contacts
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| phoneNumber | string | Yes | Phone number. Both numeric numbers and numbers encoded in URI format (for example, tel:13xxxx) are supported. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Error codes
For details about the error codes, see Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types; |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
// The tel URI format is supported since API version 15, for example, tel:13xxxx.
call.makeCall("138xxxxxxxx", (err: BusinessError) => {
if (err) {
console.error(`makeCall fail, err->Code${err.code}, message:${err.message}`);
} else {
console.info(`makeCall success`);
}
}); makeCall(phoneNumber: string): Promise<void>
Launches the call screen and displays the dialed number. This API can be called only in UIAbility. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.Applications.Contacts
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| phoneNumber | string | Yes | Phone number. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types; |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
// The tel URI format is supported since API version 15, for example, tel:13xxxx.
call.makeCall("138xxxxxxxx").then(() => {
console.info(`makeCall success`);
}).catch((err: BusinessError) => {
console.error(`makeCall fail, promise: err->Code${err.code}, message:${err.message}`);
}); makeCall(phoneNumber: string, options?: MakeCallOptions): Promise<void>
Launches the call screen and displays the dialed number. This API can be called only in UIAbility. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 24.
System capability: SystemCapability.Applications.Contacts
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| phoneNumber | string | Yes | Phone number, which can be in numeric format or tel format (for example, tel:13xxxx). |
| options | MakeCallOptions | No | Call options. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { call } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';
// Set whether to hide the dialer screen.
let makeOptions: call.MakeCallOptions = {
isHideDialScreen: true
};
call.makeCall("138xxxxxxxx", makeOptions).then(() => {
console.info(`makeCall success`);
}).catch((err: BusinessError) => {
console.error(`makeCall fail, promise: err->Code${err.code}, message:${err.message}`);
}); makeCall(context: Context, phoneNumber: string): Promise<void>
Launches 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.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Applications.Contacts
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| context | Context | Yes | Application context. |
| phoneNumber | string | Yes | Phone number. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types; |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
Example
In the sample code provided in this topic, this.context is used to obtain UIAbilityContext, where this indicates a UIAbility instance inherited from UIAbility. To use UIAbilityContext APIs on pages, see Obtaining the Context of UIAbility.
import { BusinessError } from '@kit.BasicServicesKit';
// Obtain the application context.
let context = this.getUIContext().getHostContext() as Context;
// The tel URI format is supported since API version 15, for example, tel:13xxxx.
call.makeCall(context, "138xxxxxxxx").then(() => {
console.info(`makeCall success`);
}).catch((err: BusinessError) => {
console.error(`makeCall fail, promise: err->${err.code},message:${err.message}`);
}); makeCallWithToken(phoneNumber: string, options?: MakeCallOptions): Promise<string>
Launches 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.
This API returns a verification token. You can use phoneNumber and token to implement specific capabilities, such as recording cellular downlink streams.
Since: 26.0.0
Atomic service API: This API can be used in atomic services since API version 26.0.0.
System capability: SystemCapability.Applications.Contacts
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| phoneNumber | string | Yes | Phone number. |
| options | MakeCallOptions | No | Call options. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the authentication token. |
Error codes
For details about the error codes, see Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { call } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';
// Set whether to hide the dialer screen and whether to enable custom accessibility for the app.
let makeOptions: call.MakeCallOptions = {
isHideDialScreen: true,
isCustomAccessibility: true
};
call.makeCallWithToken("138xxxxxxxx", makeOptions).then(() => {
console.info(`makeCallWithToken success`);
}).catch((err: BusinessError) => {
console.error(`makeCallWithToken fail, promise: err->Code${err.code}, message:${err.message}`);
}); 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 '@kit.BasicServicesKit';
call.hasCall((err: BusinessError, data: boolean) => {
if (err) {
console.error(`hasCall fail, err->Code${err.code}, message:${err.message}`);
} else {
console.info(`hasCall success, data->${JSON.stringify(data)}`);
}
}); 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 '@kit.BasicServicesKit';
call.hasCall().then(() => {
console.info(`hasCall success`);
}).catch((err: BusinessError) => {
console.error(`hasCall fail, promise: err->Code${err.code}, message:${err.message}`);
}); 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.info(`hasCallSync success, has call is ` + hasCall);
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 '@kit.BasicServicesKit';
call.getCallState((err: BusinessError, data: call.CallState) => {
if (err) {
console.error(`getCallState fail, err->Code${err.code}, message:${err.message}`);
} else {
console.info(`getCallState success, data->${JSON.stringify(data)}`);
}
}); 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 '@kit.BasicServicesKit';
call.getCallState().then((data: call.CallState) => {
console.info(`getCallState success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getCallState fail, promise: err->Code${err.code}, message:${err.message}`);
}); 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.info(`the call state is:` + callState);
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. |
Example
let result: boolean = call.hasVoiceCapability();
console.info(`hasVoiceCapability: ${JSON.stringify(result)}`); 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 Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types; |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
call.isEmergencyPhoneNumber("138xxxxxxxx", (err: BusinessError, data: boolean) => {
if (err) {
console.error(`isEmergencyPhoneNumber fail, err->Code${err.code}, message:${err.message}`);
} else {
console.info(`isEmergencyPhoneNumber success, data->${JSON.stringify(data)}`);
}
}); 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 Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types; |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let options: call.EmergencyNumberOptions = {slotId: 1};
call.isEmergencyPhoneNumber("112", options, (err: BusinessError, data: boolean) => {
if (err) {
console.error(`isEmergencyPhoneNumber fail, err->Code${err.code}, message:${err.message}`);
} else {
console.info(`isEmergencyPhoneNumber success, data->${JSON.stringify(data)}`);
}
}); 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 Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types; |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let options: call.EmergencyNumberOptions = {slotId: 1};
call.isEmergencyPhoneNumber("138xxxxxxxx", options).then((data: boolean) => {
console.info(`isEmergencyPhoneNumber success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`isEmergencyPhoneNumber fail, promise: err->Code:${err.code},message:${err.message}`);
}); 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 Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types; |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
call.formatPhoneNumber("138xxxxxxxx", (err: BusinessError, data: string) => {
if (err) {
console.error(`formatPhoneNumber fail, err->Code${err.code}, message:${err.message}`);
} else {
console.info(`formatPhoneNumber success, data->${JSON.stringify(data)}`);
}
}); 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 Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types; |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let options: call.NumberFormatOptions = {
countryCode: "CN"
};
call.formatPhoneNumber("138xxxxxxxx", options, (err: BusinessError, data: string) => {
if (err) {
console.error(`formatPhoneNumber fail, err->Code${err.code}, message:${err.message}`);
} else {
console.info(`formatPhoneNumber success, data->${JSON.stringify(data)}`);
}
}); 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. If this parameter is not passed, the country code CN is used by default. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the result. |
Error codes
For details about the error codes, see Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types; |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let options: call.NumberFormatOptions = {
countryCode: "CN"
};
call.formatPhoneNumber("138xxxxxxxx", options).then((data: string) => {
console.info(`formatPhoneNumber success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`formatPhoneNumber fail, promise: err->Code${err.code}, message:${err.message}`);
}); 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 Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types; |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
call.formatPhoneNumberToE164("138xxxxxxxx", "CN", (err: BusinessError, data: string) => {
if (err) {
console.error(`formatPhoneNumberToE164 fail, err->Code${err.code}, message:${err.message}`);
} else {
console.info(`formatPhoneNumberToE164 success, data->${JSON.stringify(data)}`);
}
}); 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 Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types; |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
call.formatPhoneNumberToE164("138xxxxxxxx", "CN").then((data: string) => {
console.info(`formatPhoneNumberToE164 success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`formatPhoneNumberToE164 fail, promise: err->Code${err.code}, message:${err.message}`);
}); answerCall(callback: AsyncCallback<void>): void
Answers a call. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.ANSWER_CALL or ohos.permission.MANAGE_CALL_FOR_DEVICES
System capability: SystemCapability.Telephony.CallManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the call is answered successfully, the value of err is undefined. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types; |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
call.answerCall((err: BusinessError) => {
if (err) {
console.error(`answerCall fail, err->Code${err.code}, message:${err.message}`);
} else {
console.info(`answerCall success.`);
}
}); hangUpCall(callback: AsyncCallback<void>): void
Ends a call. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.ANSWER_CALL, ohos.permission.SET_TELEPHONY_STATE, or ohos.permission.MANAGE_CALL_FOR_DEVICES
System capability: SystemCapability.Telephony.CallManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the call is hung up successfully, the value of err is undefined. Otherwise, the value is an error object. |
Error codes
For details about the error codes, see Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types; |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
call.hangUpCall((err: BusinessError) => {
if (err) {
console.error(`hangUpCall fail, err->Code${err.code}, message:${err.message}`);
} else {
console.info(`hangUpCall success.`);
}
}); rejectCall(callback: AsyncCallback<void>): void
Rejects a call. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.ANSWER_CALL or ohos.permission.MANAGE_CALL_FOR_DEVICES
System capability: SystemCapability.Telephony.CallManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the call is rejected successfully, the value of err is undefined. Otherwise, the value is an error object. |
Error codes
For details about the error codes, see Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameters types; |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
call.rejectCall((err: BusinessError) => {
if (err) {
console.error(`rejectCall fail, err->Code${err.code}, message:${err.message}`);
} else {
console.info(`rejectCall success.`);
}
}); getCallTransferInfo(type: CallTransferType, number: string): Promise<CallTransferResult>
Obtains the call forwarding status of a phone number. This API uses a promise to return the result.
Since: 26.0.0
Required permissions: ohos.permission.GET_CALL_TRANSFER_INFO
System capability: SystemCapability.Telephony.CallManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | CallTransferType | Yes | Type of call forwarding to be obtained. |
| number | string | Yes | Number used to obtain the call forwarding status. |
Return value
| Type | Description |
|---|---|
| Promise<CallTransferResult> | Promise used to return the call forwarding result. |
Error codes
For details about the error codes, see Telephony Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 801 | Capability not supported. |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8401002 | Invalid input call number. |
| 8401003 | Operation too frequent. |
Example
import { call } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';
let type: call.CallTransferType = call.CallTransferType.TRANSFER_TYPE_UNCONDITIONAL;
let number: string = "138xxxxxxxx";
call.getCallTransferInfo(type, number)
.then((data: call.CallTransferResult) => {
console.info(`getCallTransferInfo success, data->${JSON.stringify(data)}`);
})
.catch((err:BusinessError) => {
console.error(`getCallTransferInfo fail, err->Code${err.code}, message:${err.message}`);
}); Provides an option for determining whether a call is a video call.
System capability: SystemCapability.Telephony.CallManager
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| extras | boolean | No | Yes | Whether the call is a video call. - true: video call - false (default): voice call |
Enumerates call states.
System capability: SystemCapability.Telephony.CallManager
| Name | Value | Description |
|---|---|---|
| CALL_STATE_UNKNOWN | -1 | Invalid state when the call status fails to be obtained. |
| 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. |
| CALL_STATE_ANSWERED11+ | 3 | The incoming call is answered. |
Provides an option for determining whether a call is a video call.
System capability: SystemCapability.Applications.Contacts
Atomic service API: This API can be used in atomic services since API version 24.
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| isHideDialScreen | boolean | No | Yes | Whether to hide the dial screen. true: yes; false: no. The default value is false. |
| isCustomAccessibility | boolean | No | Yes | Whether the app supports custom accessibility. true: yes; false: no. The default value is false. Since: 26.0.0 Atomic service API: This API can be used in atomic services since API version 26.0.0. |
Enumerates call states.
System capability: SystemCapability.Telephony.CallManager
| Name | Value | Description |
|---|---|---|
| TEL_CALL_STATE_UNKNOWN | -1 | Invalid state when the call status fails to be obtained. |
| TEL_CALL_STATE_IDLE | 0 | No call is in progress. |
| TEL_CALL_STATE_RINGING | 1 | The call is in the ringing or waiting state. |
| TEL_CALL_STATE_OFFHOOK | 2 | At least one call is being dialed, and no new incoming call is in the ringing or waiting state. |
| TEL_CALL_STATE_ANSWERED | 3 | The incoming call is answered. |
| TEL_CALL_STATE_CONNECTED | 4 | The call is being connected or placed on hold. |
Carrier call state code.
System capability: SystemCapability.Telephony.CallManager
| Name | Value | Description |
|---|---|---|
| CCALL_STATE_UNKNOWN | -1 | Invalid state when the call status fails to be obtained. |
| CCALL_STATE_ACTIVE | 0 | The call is connected. |
| CCALL_STATE_HOLDING | 1 | The call is on hold. |
| CCALL_STATE_DIALING | 2 | The outgoing call is in the dialing process, and the peer end has not received the ringing. |
| CCALL_STATE_ALERTING | 3 | The outgoing call is in the ringing process, and the peer end is ringing. |
| CCALL_STATE_INCOMING | 4 | Indicates that an incoming call is received. |
| CCALL_STATE_WAITING | 5 | Another incoming call is received when there is an ongoing call in the same card slot. |
| CCALL_STATE_DISCONNECTED | 6 | Indicates that the call has been released. |
| CCALL_STATE_DISCONNECTING | 7 | Indicates that the call is being released. |
| CCALL_STATE_IDLE | 8 | No call is in progress. |
| CCALL_STATE_ANSWERED | 9 | The incoming call is answered. |
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 | Read-Only | Optional | Description |
|---|---|---|---|---|
| slotId | number | No | Yes | Card slot ID. The default value is 0. - 0: card slot 1 - 1: card slot 2 |
Provides an option for number formatting.
System capability: SystemCapability.Telephony.CallManager
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| countryCode | string | No | Yes | Country code, for example, CN (China). All country codes are supported. The default value is CN. |
Enumerates call transfer states.
Since: 26.0.0
System capability: SystemCapability.Telephony.CallManager
| Name | Value | Description |
|---|---|---|
| TRANSFER_DISABLE | 0 | Call transfer disabled. |
| TRANSFER_ENABLE | 1 | Call transfer enabled. |
Enumerates call transfer types.
Since: 26.0.0
System capability: SystemCapability.Telephony.CallManager
| Name | Value | Description |
|---|---|---|
| TRANSFER_TYPE_UNCONDITIONAL | 0 | Call forwarding unconditional. |
| TRANSFER_TYPE_BUSY | 1 | Call forwarding busy. |
| TRANSFER_TYPE_NO_REPLY | 2 | Call forwarding on no reply. |
| TRANSFER_TYPE_NOT_REACHABLE | 3 | Call forwarding on no user not reachable. |
Defines the call transfer result.
Since: 26.0.0
System capability: SystemCapability.Telephony.CallManager
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| status | TransferStatus | No | No | Enumerates call transfer states. |
| startHour | number | No | No | Hour in the start time. The value ranges from 0 to 23. |
| startMinute | number | No | No | Minute in the start time. The value ranges from 0 to 59. |
| endHour | number | No | No | Hour in the end time. The value ranges from 0 to 23. |
| endMinute | number | No | No | Minute in the end time. The value ranges from 0 to 59. |