HarmonyOS鸿蒙Next应用开发实战--手机拨号功能实现

HarmonyOS鸿蒙Next应用开发实战–手机拨号功能实现

实现跳转到拨号页面并填充号码:

Intent transferDialogKey=new Intent();
Operation operation=new Intent.OperationBuilder()
        .withAction(IntentConstants.ACTION_DIAL)
        .withUri(Uri.parse("tel:"+"12345678901"))
        .build();
transferDialogKey.setOperation(operation);
startAbility(transferDialogKey);

类似我们在小程序、传统APP里,点击电话,会自动到拨号页面,点击即可实现拨打功能。


更多关于HarmonyOS鸿蒙Next应用开发实战--手机拨号功能实现的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

这个简单,我立刻记笔记

更多关于HarmonyOS鸿蒙Next应用开发实战--手机拨号功能实现的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中实现手机拨号功能,首先需要在config.json中声明ohos.permission.PLACE_CALL权限。然后,使用@ohos.telephony模块的call方法进行拨号。以下是一个简单的示例代码:

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

function makePhoneCall(phoneNumber) {
    call.makeCall(phoneNumber)
        .then(() => {
            console.log('拨号成功');
        })
        .catch((err) => {
            console.error('拨号失败:', err);
        });
}

// 调用示例
makePhoneCall('10086');

确保在使用前,应用已获得拨号权限,并在config.json中正确配置权限。

回到顶部