HarmonyOS Scan Kit 自定义扫码返回1000500001
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { scanBarcode, scanCore, customScan } from '@kit.ScanKit';
let options: scanBarcode.ScanOptions = {
scanTypes: [scanCore.ScanType.ALL],
enableMultiMode: true,
enableAlbum: true
};
@Entry
@Component
struct customScanPage {
// 设置预览流高度,默认单位: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]', 'Succeeded in loading, onLoad is called.');
// 获取XComponent的surfaceId
let surfaceId: string = this.mXComponentController.getXComponentSurfaceId();
hilog.info(0x0001, '[Scan Sample]', `Succeeded in getting surfaceId: ${surfaceId}`);
// 设置ViewControl相应字段
let viewControl: customScan.ViewControl = {
width: this.cameraWidth,
height: this.cameraHeight,
surfaceId: surfaceId
};
customScan.init(options);
customScan.start(viewControl).then((scanResult: Array<scanBarcode.ScanResult>) => {
hilog.info(0x0001, '[Scan Sample]', `Succeeded in getting ScanResult by promise, scanResult is ${JSON.stringify(scanResult)}`);
}).catch((error: BusinessError) => {
hilog.error(0x0001, '[Scan Sample]', `Failed to get ScanResult by promise. Code: ${error.code}, message: ${error.message}`);
});
})// 预览流宽、高,默认单位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.
代码为示例代码
问题:
相机权限授权了在跳转此页面进行扫码展示,但是进入就会报错Code: 1000500001, message: The internal error.
HarmonyOS
赞
收藏 0
回答 1
相关问题
HarmonyOS Scan kit自定义扫码控件报错 ,错误码:1000500001
766浏览 • 1回复 待解决
使用Scan Kit(统一扫码服务)调用扫码
1980浏览 • 1回复 待解决
HarmonyOS 初始化自定义界面扫码的时候报错1000500001
675浏览 • 1回复 待解决
HarmonyOS 自定义扫码咨询
649浏览 • 1回复 待解决
HarmonyOS 使用自定义扫码customScan,进入后台后调用stop接口报错1000500001
713浏览 • 1回复 待解决
自定义扫码功能,API11提供的自定义扫码功能,如何自定义扫码识别框的宽高?
2756浏览 • 1回复 待解决
HarmonyOS 如何自定义扫码页面
673浏览 • 1回复 待解决
使用Scan Kit(统一扫码服务),通过接数组生成码图
1112浏览 • 1回复 待解决
使用Scan Kit(统一扫码服务),通过文本生成生成码
1132浏览 • 1回复 待解决
HarmonyOS 自定义扫码界面功能自定义高度后报错
836浏览 • 1回复 待解决
HarmonyOS customScan.start扫码报错1000500001
912浏览 • 1回复 待解决
HarmonyOS 自定义扫码的恢复态API
598浏览 • 1回复 待解决
自定义界面扫码预览画面出现拉伸
2588浏览 • 1回复 待解决
HarmonyOS Scan Kit使用中前后台切换后报错1000500001
951浏览 • 1回复 待解决
Scan Kit无法识别多个码图
2424浏览 • 1回复 待解决
HarmonyOS ScanKit自定义界面扫码,相机流无法预览
933浏览 • 1回复 待解决
HarmonyOS 自定义界面扫码当扫到多个码时如何处理
945浏览 • 1回复 待解决
HarmonyOS 平板上使用扫一扫报错:扫一扫服务异常,是否继续?参考码:1000500001
832浏览 • 1回复 待解决
HarmonyOS 自定义扫一扫功能
787浏览 • 1回复 待解决
HarmonyOS 自定义扫码界面(customScan)和默认扫描 无法自动聚焦
1107浏览 • 1回复 待解决
HarmonyOS Scan Kit服务中码图生成如何添加logo图片?
999浏览 • 1回复 待解决
HarmonyOS使用Scan kit进行文本生成码图异常
782浏览 • 1回复 待解决
HarmonyOS在自定义扫码中,如何获取当前设备的相机焦距区间?
875浏览 • 1回复 待解决
HarmonyOS 自定义界面扫码,上滑退到后台再打开预览流就没了
879浏览 • 1回复 待解决
API参考里面给的是部分的代码不是整个端到端的流程。当前代码的问题是没有申请相机的权限。 可以参考自定义扫码指南查看
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/scan-customscan-V5
几个要点:
module.json5 中添加camera的权限声明
拉起自定义扫码界面时需要动态申请相机的权限,等待用户授权
用户授权后在启动相机流进行扫码
获取扫码结果 附权限声明module.json5: