HarmonyOS customScan.init报错1000500001?

代码片段:

async onPageShow() {
  await this.requestCameraPermission();
  let options: scanBarcode.ScanOptions = {
    scanTypes: [scanCore.ScanType.ALL],
    enableMultiMode: true,
    enableAlbum: true
  }
  this.setDisplay();
  try {
    customScan.init(options);
  } catch (error) {
    hilog.error(0x0001, this.TAG, 'init fail, error: %{public}s ', JSON.stringify(error));
  }
}

运行后customScan.init报错1000500001。

阅读 490
1 个回答

由于未在module.json5添加相机权限导致if (this.userGrant)这里判断没有正确初始化XComponent,最终导致customScan.init失败,请再添加完权限后试试参考:

#module.json5
"requestPermissions":[
      {
        "name": "ohos.permission.INTERNET"
      },
      {
        "name": "ohos.permission.ACCESS_BLUETOOTH",
        "reason": "$string:access_bluetooth_reason",
        "usedScene": {
          "abilities": ["Bluetooth2Ability"]
        }
      },
      {
        "name": "ohos.permission.CAMERA",
        "reason": "$string:access_bluetooth_reason",
        "usedScene": {
          "abilities": ["EntryAbility"]
        }
      }
    ],
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进