HarmonyOS 鸿蒙Next大佬们麻烦看看,为什么下面这个扫一扫的demo报1000500001,现象是黑屏呀
HarmonyOS 鸿蒙Next大佬们麻烦看看,为什么下面这个扫一扫的demo报1000500001,现象是黑屏呀 MatePad用Api12,DevEco Studio版本是5.0.5.300,扫一扫demo,报1000500001错误,下面是代码,我该怎么操作?
import { Logger } from '../common/utils/Logger';
import { customScan, scanBarcode } from '@kit.ScanKit';
import { BusinessError } from '@kit.BasicServicesKit';
@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(() => {
Logger.info('[Scan Sample] '+ 'onLoad is called')
// 获取XComponent的surfaceId
let surfaceId: string = this.mXComponentController.getXComponentSurfaceId();
Logger.info( '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) {
Logger.error( '[Scan Sample] start failed , error: '+ JSON.stringify(error))
return;
}
Logger.info( '[Scan Sample] callback scan result: '+ JSON.stringify(scanResult))
});
} catch (error) {
Logger.error( '[Scan Sample] start failed , error: '+ 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 })
}
}
更多关于HarmonyOS 鸿蒙Next大佬们麻烦看看,为什么下面这个扫一扫的demo报1000500001,现象是黑屏呀的实战教程也可以访问 https://www.itying.com/category-93-b0.html
3 回复
楼主提供一下全量日志看看
另外确认一下是否有动态申请相机权限,是否有调用customScan.init
更多关于HarmonyOS 鸿蒙Next大佬们麻烦看看,为什么下面这个扫一扫的demo报1000500001,现象是黑屏呀的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
嘿嘿