申请权限ohos.permission.CAMERA以使用相机时,可以用camera picker替代,不用申请权限吗?

申请权限ohos.permission.CAMERA以使用相机时,可以用camera picker替代,不用申请权限吗?


HarmonyOS
2024-11-13 11:46:53
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

可以不用申请权限,参考如下demo。

import picker from '@ohos.multimedia.cameraPicker'; 
import camera from '@ohos.multimedia.camera'; 
import common from '@ohos.app.ability.common'; 
import { BusinessError } from '@ohos.base'; 
 
 
@Entry 
@Component 
struct Index { 
  mContext = getContext(this) as common.Context; 
 
  async demo() { 
    try { 
      let pickerProfile: picker.PickerProfile = { 
        cameraPosition: camera.CameraPosition.CAMERA_POSITION_BACK 
      }; 
      let pickerResult: picker.PickerResult = await picker.pick(this.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}`); 
    } 
  } 
 
  @State message: string = 'Hello World'; 
 
  build() { 
    Row() { 
      Column() { 
        Button(this.message) 
          .onClick(()=>{ 
            this.demo() 
          }) 
 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
分享
微博
QQ
微信
回复
2024-11-13 17:01:57
相关问题
HarmonyOS 动态申请权限申请不了
892浏览 • 1回复 待解决
import camera from '@ohos.multimedia.camera'
1558浏览 • 1回复 待解决
HarmonyOS 位置权限申请
1017浏览 • 1回复 待解决