【Harmony声明 ohos.permission.ANSWER_CALL 权限,安装报错install failed due to grant request permissions failed

 

【关键字】

拨号 / 报错 / 权限

【问题描述】

声明 ohos.permission.ANSWER_CALL 权限,安装报错install failed due to grant request permissions failed

【Harmony声明 ohos.permission.ANSWER_CALL 权限,安装报错install failed due to grant request permissions failed_第1张图片

【解决方案】

从如下四个方面进行排查:

1、ohos.permission.ANSWER_CALL为系统应用权限,不支持其他应用使用,可通过startAbility的方式跳转到拨号页面;

2、如需要申请ohos.permission.WRITE_CONTACTS权限,配置方式请参见配置文件权限声明;

说明:该权限为system_basic,APL级别的权限,需要申请白名单。

3、调用call.hasVoiceCapability()接口确认当前设备是否支持拨号。如果设备支持呼叫能力,则继续跳转到拨号界面,并显示拨号的号码;

4、调用 call.dialCall()接口,拨打电话。

请参考以下Demo:

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('16888888888', (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 Index {
@State message: string = 'Hello World';

build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
startCallDialog(context);
})
}
.width('100%')
}
.height('100%')
}
}

你可能感兴趣的:(harmonyos)