HarmonyOS 官方有提供可以直接扫码的功能吗

HarmonyOS
2024-12-27 17:21:29
833浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

可以使用Scan Kit参考文档:

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/scan-scanbarcode-V5

import { scanCore, scanBarcode } from '@kit.ScanKit';
// 导入默认界面需要的日志模块和错误码模块
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct ScanBarCodePage {
  build() {
    Column() {
      Row() {
        Button("Promise with options")
          .backgroundColor('#0D9FFB')
          .fontSize(20)
          .fontColor('#FFFFFF')
          .fontWeight(FontWeight.Normal)
          .align(Alignment.Center)
          .type(ButtonType.Capsule)
          .width('90%')
          .height(40)
          .margin({ top: 5, bottom: 5 })
          .onClick(() => {
            // 定义扫码参数options
            let options: scanBarcode.ScanOptions = {
              scanTypes: [scanCore.ScanType.ALL],
              enableMultiMode: true,
              enableAlbum: true
            };
            try {
              scanBarcode.startScanForResult(getContext(this), options).then((result: scanBarcode.ScanResult) => {
                // 收到扫码结果后返回
                hilog.info(0x0001, '[Scan CPSample]', 'Promise scan result: %{public}s', JSON.stringify(result));
              }).catch((error: BusinessError) => {
                hilog.error(0x0001, '[Scan CPSample]', 'Promise error: %{public}s', JSON.stringify(error));
              });
            } catch (error) {
              hilog.error(0x0001, '[Scan CPSample]', 'failReason: %{public}s', JSON.stringify(error));
            }
          })
      }
      .height('100%')
    }
    .width('100%')
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-27 20:14:22


相关问题
HarmonyOS 是否功能
752浏览 • 1回复 待解决
HarmonyOS 能否提供demo代码
919浏览 • 1回复 待解决
实现哪些 ,有人知道
1875浏览 • 1回复 待解决
HarmonyOS 功能应该看哪个文档
925浏览 • 1回复 待解决
JS如何实现手机功能
3698浏览 • 1回复 待解决
HarmonyOS H5调用原生功能
968浏览 • 1回复 待解决
HarmonyOS APP可以生成二维安装
1516浏览 • 1回复 待解决
HarmonyOS是否官方提供加锁方法
1078浏览 • 1回复 待解决
Arkts开发 api9 中怎么实现功能
4036浏览 • 1回复 待解决
HarmonyOS 直达问题
772浏览 • 1回复 待解决
HarmonyOS 需要demo
836浏览 • 1回复 待解决
HarmonyOS 功能Demo
683浏览 • 1回复 待解决