【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

cke_1073.png

【解决方案】

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

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%')
}
}
  • 10
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值