> 文档中心 > HarmonyOS应用API-拨打电话

HarmonyOS应用API-拨打电话

1.import需要的模块

// import需要的模块

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

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

2.调用hasVoiceCapability()接口获取当前设备呼叫能力,如果支持继续下一步如果不支持则无法发起呼叫。

let isSupport = call.hasVoiceCapability();

if (!isSupport) {

    console.log("not support voice capability, return.");

    return;

}

3.跳转到拨号界面,并显示拨号的号码。

call.makeCall("13xxxx", (err)=> {

    if (!err) {

        console.log("make call success.");

    } else {

        console.log("make call fail, err is:" + JSON.stringify(err));

    }

});