app上架被拒,提示项目不可以使用WRITE\_IMAGEVIDEO权限,保存图片和视频需要使用安全控件,但是安全控件UI不符合需求,
现在思路是想着在安全按钮上面盖一层布局以满足UI要求。
参考hitTestBehavior的用法,现在已经把id为‘camera\_button’的父容器的点击事件,透传到了安全控件保存按钮,
但是SaveButtonOnClickResult为Fail,权限授权失败;麻烦帮忙看下,怎么写可以让父容器的点击事件透传到保存按钮时,可以授权成功?
SaveButtonPage.ets
import { promptAction } from '@kit.ArkUI';
@Entry
@Component
struct SaveButtonPage {
build() {
RelativeContainer() {
Row() {
Stack({ alignContent: Alignment.Top }) {
// 安全控件保存按钮
SaveButton()
.offset({
x: 0,
y: 5
})
.constraintSize({ maxWidth: 50, maxHeight: 50 })
.onClick(async (event: ClickEvent, result: SaveButtonOnClickResult) => {
console.log('testEvent click SaveButton')
if (result == SaveButtonOnClickResult.SUCCESS) {
console.log('testEvent SaveButtonOnClickResult create asset success')
} else {
console.error('testEvent SaveButtonOnClickResult create asset failed');
}
})
// 安全控件保存按钮的上层遮罩(id:mask)
Row() {
Image($r('app.media.recording_lite_record_done_white'))
.width(40)
.height(40)
.id('inner-icon')
.enabled(false)
}
.width(65)
.height(65)
.id('mask')
.justifyContent(FlexAlign.Center)
.borderRadius(35)
.backgroundColor('#FFA04F')
.id('mask')
.hitTestBehavior(HitTestMode.None)
.onClick(() => {
console.log('testEvent click mask')
})
}
}
.width(65)
.aspectRatio(1)
.borderRadius(35)
.backgroundColor('#FFA04F')
.id('camera_button')
.justifyContent(FlexAlign.Center)
.hitTestBehavior(HitTestMode.None)
.alignRules({
bottom: { anchor: '__container__', align: VerticalAlign.Bottom },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.margin({
bottom: 33
})
.onClick(() => {
console.log('testEvent click outer rl')
})
}
}
}
因为安全控件的约束与限制,安全控件被其他组件或窗口遮挡会导致授权失败,可以在开发设备日志中筛选SecurityComponentCheckFail关键字查看失败的具体原因:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/security-component-overview-V5\#约束与限制
若是要申请使用受限权限可以参考此文档:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/declare-permissions-in-acl-V5