#鸿蒙通关秘籍#如何通过Callback方式获取扫码结果?

HarmonyOS
2024-11-29 15:46:44
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
墨雨尘API

使用scanBarcode模块的startScanForResult方法可以通过Callback方式来异步获取扫码结果。下面是实现示例:

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

scanBarcode.startScanForResult(getContext(this), (error, result) => {
  if (error) {
    hilog.error(0x0001, '[Scan Sample]', `Failed to get ScanResult by callback. Code: ${error.code}, message: ${error.message}`);
    return;
  }
  hilog.info(0x0001, '[Scan Sample]', `Succeeded in getting ScanResult by callback, result is ${JSON.stringify(result)}`);
});
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
分享
微博
QQ
微信
回复
2024-11-29 17:08:45


相关问题
相册识别多失败
2651浏览 • 1回复 待解决
JS如何实现手机功能?
3710浏览 • 1回复 待解决
HarmonyOS 需要demo
868浏览 • 1回复 待解决
HarmonyOS 直达问题
798浏览 • 1回复 待解决