HarmonyOS 鸿蒙Next Scan Kit生成二维码问题
HarmonyOS 鸿蒙Next Scan Kit生成二维码问题
使用官方api代码:
- @Entry
- @Component
- struct Index {
- @State pixelMap: image.PixelMap | undefined = undefined
- build() {
- Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
- Button(‘generateBarcode Promise’).onClick(() => {
- // 以QR码为例,码图生成参数
- this.pixelMap = undefined;
- let content: string = ‘huawei’;
- let options: generateBarcode.CreateOptions = {
- scanType: scanCore.ScanType.QR_CODE,
- height: 400,
- width: 400
- }
- // 码图生成接口,成功返回PixelMap格式图片
- generateBarcode.createBarcode(content, options).then((pixelMap: image.PixelMap) => {
- this.pixelMap = pixelMap;
- }).catch((error: BusinessError) => {
- hilog.error(0x0001, ‘[generateBarcode]’, ‘promise error : %{public}s’, JSON.stringify(error));
- })
- })
- // 获取生成码后显示
- if (this.pixelMap) {
- Image(this.pixelMap).width(300).height(300).objectFit(ImageFit.Contain)
- }
- }
- .width(‘100%’)
- .height(‘100%’)
- }
- }
上述代码使用时报错:
08-27 16:34:06.329 7520-7545 C02805/InputKeyFlow com.examp…lication I [][OnPointerEvent:188] ac: down: 170
08-27 16:34:06.330 7520-7545 C02805/InputKeyFlow com.examp…lication I [P:D:170][OnPointerEvent:489] id:170 recv
08-27 16:34:06.330 7520-7545 C04213/InputKeyFlow com.examp…lication I [input_transfer_station.cpp] OnInputEvent<82>: eid:4,InputId:170,wid:42,action:2
08-27 16:34:06.330 7520-7545 C04200/WindowSessionImpl com.examp…lication E <1509>GetDecorHeight: Get app window decor height failed
08-27 16:34:06.331 7520-7545 C0420c/WMSEvent com.examp…lication I [window_session_impl.cpp] NotifyPointerEvent<2706>: Input id:170
08-27 16:34:06.331 7520-7545 C03900/Ace com.examp…lication I [mmi_event_convertor.cpp(512)-(-1:100000:singleton)] pointdown windowId: 42
08-27 16:34:06.331 7520-7545 C04213/InputKeyFlow com.examp…lication I [window_scene_session_impl.cpp] ConsumePointerEventInner<614>: InputId:170,wid:42,pointId:0,sourceType:2,winRect:[0,0,1260,2720],needNotifyEvent:1
08-27 16:34:06.332 7520-7520 C03950/InputKeyFlow com.examp…lication I [pipeline_context.cpp(2023)-(100000:100000:scope)] InputTracking id:170, fingerId:0, x=619.000, y=1365.000 type=0, inject=0
08-27 16:34:06.332 7520-7520 C03950/InputKeyFlow com.examp…lication I [event_manager.cpp(215)-(100000:100000:scope)] InputTracking id:170, touch test hitted node info: fingerId: 0{ tag: Button, inspectorId: , frameRect: RectT (473.50, 1186.50) - [313.00 x 130.00], depth: 6 };
08-27 16:34:06.332 7520-7520 C03950/InputKeyFlow com.examp…lication I [event_manager.cpp(304)-(100000:100000:scope)] InputTracking id:170, touch test hitted recognizer type info: recognizer type ClickRecognizer node info: { tag: Button, inspectorId: };
08-27 16:34:06.332 7520-7520 C03950/InputKeyFlow com.examp…lication I [click_recognizer.cpp(195)-(100000:100000:scope)] Id:170, click 0 down, ETF: 0, CTP: 0, state: 0
08-27 16:34:06.333 7520-7520 C03919/AceInputTracking com.examp…lication I [event_manager.cpp(1934)-(100000:100000:scope)] Consumed new event id=170 in ace_container, lastEventInfo: id:-1
08-27 16:34:06.377 7520-7545 C02805/InputKeyFlow com.examp…lication I [][OnPointerEvent:188] ac: up: 171
08-27 16:34:06.377 7520-7545 C02805/InputKeyFlow com.examp…lication I [P:U:171][OnPointerEvent:489] id:171 recv
08-27 16:34:06.377 7520-7545 C04213/InputKeyFlow com.examp…lication I [input_transfer_station.cpp] OnInputEvent<82>: eid:5,InputId:171,wid:42,action:4
08-27 16:34:06.377 7520-7545 C0420c/WMSEvent com.examp…lication I [window_session_impl.cpp] NotifyPointerEvent<2706>: Input id:171
08-27 16:34:06.377 7520-7545 C04213/InputKeyFlow com.examp…lication I [window_scene_session_impl.cpp] ConsumePointerEventInner<614>: InputId:171,wid:42,pointId:0,sourceType:2,winRect:[0,0,1260,2720],needNotifyEvent:1
08-27 16:34:06.377 7520-7520 C03950/InputKeyFlow com.examp…lication I [pipeline_context.cpp(2023)-(100000:100000:scope)] InputTracking id:171, fingerId:0, x=619.000, y=1365.000 type=1, inject=0
08-27 16:34:06.377 7520-7520 C03950/InputKeyFlow com.examp…lication I [click_recognizer.cpp(256)-(100000:100000:scope)] Id:171, click 0 up, state: 0
08-27 16:34:06.377 7520-7520 C0391e/AceGesture com.examp…lication I [click_recognizer.cpp(291)-(100000:100000:scope)] Click try accept
08-27 16:34:06.377 7520-7520 C03950/InputKeyFlow com.examp…lication I [click_recognizer.cpp(148)-(100000:100000:scope)] Click accepted, tag: Button
08-27 16:34:06.378 7520-7520 A03d00/JSAPP com.examp…lication I Scankit generateBarcode device type is emulator
08-27 16:34:06.380 7520-7520 C03f00/ArkCompiler com.examp…lication E [default] [Call:3324] occur exception need return
08-27 16:34:06.380 7520-7520 C03f00/ArkCompiler com.examp…lication E [ecmascript] Pending exception before ExecutePendingJob called, in line:5046, exception details as follows:
08-27 16:34:06.380 7520-7520 C03f00/ArkCompiler com.examp…lication E [ecmascript] [object Object]
08-27 16:34:06.380 7520-7520 C01320/AAFwkJsEnv com.examp…lication E [uncaught_exception_callback.cpp(GetNativeStrFromJsTaggedObj:41)]Failed to convert value from key.
08-27 16:34:06.380 7520-7520 C01320/AAFwkJsEnv com.examp…lication E [uncaught_exception_callback.cpp(GetNativeStrFromJsTaggedObj:41)]Failed to convert value from key.
08-27 16:34:06.380 7520-7520 C01320/AAFwkJsEnv com.examp…lication E [uncaught_exception_callback.cpp(GetNativeStrFromJsTaggedObj:41)]Failed to convert value from key.
08-27 16:34:06.380 7520-7520 C01320/AAFwkJsEnv com.examp…lication E [uncaught_exception_callback.cpp(operator():75)]errorStack is empty
08-27 16:34:06.380 7520-7520 C03919/AceInputTracking com.examp…lication I [event_manager.cpp(1934)-(100000:100000:scope)] Consumed new event id=171 in ace_container, lastEventInfo: id:-1
08-27 16:34:11.385 7520-7688 C01719/ffrt com.examp…lication W 129:~WorkerThread:65 WorkerThread enter destruction
请问是什么原因?本人用的 模拟器
关于HarmonyOS 鸿蒙Next Scan Kit生成二维码问题的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。
你好,可爱的开发者
关于“Scan Kit生成二维码问题”,我们不妨先对编译器出现的错误信息进行解读。有一条错误信息是“Scankit generateBarcode device type is emulator”,通俗的说,就是当前的 Scan Kit 功能不支持在模拟器上运行。这意味着我们需要使用真实的硬件设备来进行测试,而不是在模拟器上操作。
我已经审视了您的代码示例,确认其能够在真实设备上成功生成二维码。因此,建议你将测试环境从模拟器转移到实际的设备上