HarmonyOS Scan kit自定义扫码控件报错 ,错误码:1000500001

根据下面网站DEMO信息

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/scan-customscan-api-V5

使用了customScan中的原样代码,代码如下:

import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { scanBarcode, customScan } from '@kit.ScanKit';

@Entry
@Component
struct ScanQTCode {
  // 设置预览流高度,默认单位:vp
  @State cameraHeight: number = 640
  // 设置预览流宽度,默认单位:vp
  @State cameraWidth: number = 360
  private mXComponentController: XComponentController = new XComponentController();

  build() {
    Stack() {
      XComponent({
        id: 'componentId',
        type: 'surface',
        controller: this.mXComponentController
      })
        .onLoad(() => {
          hilog.info(0x0001, '[Scan Sample]', 'onLoad is called')
          // 获取XComponent的surfaceId
          let surfaceId: string = this.mXComponentController.getXComponentSurfaceId();
          hilog.info(0x0001, 'viewControl', `onLoad surfaceId: ${surfaceId}`);
          // 设置ViewControl相应字段
          let viewControl: customScan.ViewControl = {
            width: this.cameraWidth,
            height: this.cameraHeight,
            surfaceId: surfaceId
          };
          try {
            customScan.start(viewControl, (error: BusinessError, scanResult: Array<scanBarcode.ScanResult>) => {
              if (error) {
                hilog.error(0x0001, '[Scan Sample]', 'start failed , error: %{public}s', JSON.stringify(error))
                return;
              }
              hilog.info(0x0001, '[Scan Sample]', 'callback scan result: %{public}s', JSON.stringify(scanResult))
            });
          } catch (error) {
            hilog.error(0x0001, '[Scan Sample]', 'start failed , error: %{public}s', JSON.stringify(error))
          }
        })
          // 预览流宽、高,默认单位vp,支持px、lpx、vp
        .height(this.cameraHeight)
        .width(this.cameraWidth)
        .position({ x: 0, y: 0 })
    }
    .alignContent(Alignment.Bottom)
    .height('100%')
    .width('100%')
    .position({ x: 0, y: 0 })
  }
};
  • 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.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
HarmonyOS
2024-12-27 18:42:53
3061浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

API参考里面给的是部分的代码不是整个端到端的流程。当前代码的问题是没有申请相机的权限。

可以参考自定义扫码指南查看

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/scan-customscan-V5

几个要点:

  1. module.json5 中添加camera的权限声明

2.拉起自定义扫码界面时需要动态申请相机的权限,等待用户授权

  1. 用户授权后在启动相机流进行扫码

4.获取扫码结果

附权限声明module.json5:

"requestPermissions":[
{
  "name" : "ohos.permission.CAMERA",
  "reason": "$string:reason",
  "usedScene": {
    "abilities": [
    "FormAbility"
    ,
    "when":"inuse"
  }
}
],
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
分享
微博
QQ
微信
回复
2024-12-27 20:33:37
相关问题
HarmonyOS customScan.start报错1000500001
916浏览 • 1回复 待解决
HarmonyOS 自定义咨询
653浏览 • 1回复 待解决
HarmonyOS 如何自定义页面
674浏览 • 1回复 待解决
HarmonyOS 指纹报错没有错误码
780浏览 • 1回复 待解决
HarmonyOS 自定义的恢复态API
599浏览 • 1回复 待解决
Socket连接报错错误码88
2612浏览 • 1回复 待解决
HarmonyOS上传app包报错错误码996
739浏览 • 1回复 待解决
自定义界面预览画面出现拉伸
2588浏览 • 1回复 待解决
Scan Kit无法识别多个
2424浏览 • 1回复 待解决
HarmonyOS 错误码7400201
1012浏览 • 1回复 待解决
提问
该提问已有0人参与 ,帮助了1人