HarmonyOS 拨打电话功能?

App有个场景会显示电话号码,用户点击号码后携带号码跳转拨号页面,在HarmonyOS上该功能如何实现?

阅读 654
1 个回答

参考示例如下:

import call from '@ohos.telephony.call';
import { BusinessError } from '@ohos.base';

function startCallDialog(): void {
  let isSupport = call.hasVoiceCapability();
  if (!isSupport) {
    console.error('Not support voice capability.');
    return;
  }
  call.makeCall('电话号码', (err: BusinessError) => {
    if (err) {
      console.error(`Failed to make call. Code is ${err.code}, Message is ${err.message}`);
      return;
    }
    console.info('Succeeded in making call.');
  })
}

@Entry
@Component
struct Phone {
  build() {
    Row() {
      Column() {
        Button('拨打电话')
          .onClick(() => {
            startCallDialog();
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进