如果仅是需要拉起系统相机拍摄一张照片、录制一段视频,可直接使用CameraPicker,无需申请相机权限,直接拉起系统相机完成拍摄,参考链接: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-camerapicker-V5参考demo:import { cameraPicker as picker } from '@kit.CameraKit'; import { camera } from '@kit.CameraKit'; import { common } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let mContext = getContext(this) as common.Context; async function demo() { try { let pickerProfile: picker.PickerProfile = { cameraPosition: camera.CameraPosition.CAMERA_POSITION_BACK }; let pickerResult: picker.PickerResult = await picker.pick(mContext, [picker.PickerMediaType.PHOTO, picker.PickerMediaType.VIDEO], pickerProfile); console.log("the pick pickerResult is:" + JSON.stringify(pickerResult)); } catch (error) { let err = error as BusinessError; console.error(`the pick call failed. error code: ${err.code}`); } } @Entry @Component struct cameraExample{ build(){ Button().width(100).height(100) .onClick(()=>{ demo() }) } }获取用户相册是需要权限:申请相册管理模块权限ohos.permission.READ\_IMAGEVIDEO,参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/photoaccesshelper-useralbum-guidelines-V5\#获取用户相册
如果仅是需要拉起系统相机拍摄一张照片、录制一段视频,可直接使用CameraPicker,无需申请相机权限,直接拉起系统相机完成拍摄,参考链接: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-camerapicker-V5
参考demo:
获取用户相册是需要权限:申请相册管理模块权限ohos.permission.READ\_IMAGEVIDEO,参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/photoaccesshelper-useralbum-guidelines-V5\#获取用户相册