前置:
Api:8
语言:js开发
需要权限:
ohos.permission.PLACE_CALL

api参考地址:
开始:
1.创建项目:

2.示例代码
test.ml
- <div class="container">
- <input type="number" value="" on:change="getCallNumber" placeholder="请输入号码"></input>
- <button type="capsule" class="btn" onclick="call">拨打电话</button>
- </div>
-
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")
- }
- }
- }
-