HarmonyOS应用开发JSAPI-js拨打电话call
前置:
Api:8
语言:js开发
需要权限:
ohos.permission.PLACE_CALL
api参考地址:
文档中心
开始:
1.创建项目:
2.示例代码
test.ml
test.css
.container { flex-direction: column; justify-content: center; align-items: center; width: 100%; height: 100%;}.btn { font-size: 50px; margin: 10px;}
test.js
import call from '@ohos.telephony.call';import prompt from '@system.prompt';export default { data: { num:null }, getCallNumber(e){ this.num = e.value }, call() { // 调用查询能力接口 let isSupport = call.hasVoiceCapability(); if (isSupport) { if(this.num != null){ // 如果设备支持呼叫能力,则继续跳转到拨号界面,并显示拨号的号码 call.makeCall(this.num, (err) => { if (!err) { console.info("make call success"); } else { console.info("make call fail, err is:" + JSON.stringify(err)); } }); }else{ prompt.showToast({ message:"您拨打的是空号" }) } } else { console.info("NOT SUPPORT") } }}
4.代码地址
(HarmonyOSAPP开发相关组件: 深圳市蛟龙腾飞网络科技有限公司 - Gitee.com)