npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cordova-ohos/phonegap-plugin-barcodescanner

v8.1.0

Published

Cordova statusbar Plugin

Downloads

123

Readme

phonegap-plugin-barcodescanner 高效条码扫描插件

一款专为 Cordova/PhoneGap 混合移动应用打造的条码与二维码扫描插件,基于原生平台扫描能力开发,支持多码制识别、实时预览、闪光灯控制及本地图片解析等核心功能。具备识别速度快、准确率高、兼容性强、轻量化等特点,可广泛应用于商品溯源、移动支付、资产管理、票务验证等场景。

功能特性

  • 多码制全面支持:覆盖常见一维码(如 EAN-13、UPC-A、Code 128)和二维码(如 QR Code、Data Matrix、Aztec),支持自定义启用/禁用特定码制

  • 原生扫描引擎:基于 HamonyOS 原生扫描能力开发,识别速度≤300ms,准确率≥98%(清晰条码场景)

  • 实时预览与对焦:支持高清实时预览(最高 1080P),支持自动对焦、手动点击对焦及连续对焦模式,适配不同距离扫描需求

  • 辅助扫描功能:集成闪光灯控制(明暗环境自适应)、扫描框引导(提高识别效率)、震动/声音反馈(扫描成功提示)

  • 本地图片解析:支持从相册选择图片或传入图片路径,解析图片中的条码信息,适配多种图片格式(JPG、PNG、GIF 等)

  • 权限智能管理:自动检测并请求相机、相册权限,提供权限申请结果回调,支持权限拒绝后的引导处理

  • 离线全功能支持:所有扫描与解析功能均本地完成,无需依赖网络,满足无网环境使用需求

安装方法

确保已创建 Cordova/PhoneGap 项目(若未创建,执行 cordova create barcodeApp com.example.barcodeapp BarcodeAppphonegap create barcodeApp 创建),进入项目根目录后选择以下方式安装:

1. 基础版安装

适用于大多数场景,直接从 npm 仓库安装稳定版:

# 安装hcordova
npm install -g hcordova

# 安装最新稳定版扫描插件
hcordova plugin add phonegap-plugin-barcodescanner

# 安装指定版本(示例:1.0.0 版本)
hcordova plugin add [email protected] --platform ohos

2. 从 GitCode 安装开发版

适用于需要体验最新功能的开发者,从 GitHub 仓库直接安装:


# 安装开发版插件
hcordova plugin add https://gitcode.com/OpenHarmony-Cordova/phonegap-plugin-barcodescanner.git --platform ohos

3. 离线安装(本地包)

适用于无网络环境,先下载插件包到本地,再执行离线安装:


# 下载插件包到本地(示例路径:~/Downloads/phonegap-plugin-barcodescanner)
# 执行离线安装
cordova plugin add ~/Downloads/phonegap-plugin-barcodescanner

卸载方法

进入项目根目录,执行以下命令卸载插件,卸载后建议重新构建项目以清理残留文件:


# 卸载扫描插件
hcordova plugin remove phonegap-plugin-barcodescanner

# 指定HarmonyOS卸载
hcordova plugin remove phonegap-plugin-barcodescanner --platform ohos

核心概念

1. 插件命名空间

插件通过全局对象 cordova.plugins.barcodeScanner 暴露所有 API 方法,所有操作均需通过该命名空间调用,避免与其他插件冲突。

2. 扫描模式

插件支持两种核心扫描模式,可根据业务场景选择:

  • 实时扫描模式:打开相机实时预览并识别条码,适用于直接扫描实体条码的场景(如商品扫码、票务验证),仅支持单次扫描

  • 图片解析模式:解析本地图片文件中的条码信息,适用于扫描已保存的条码图片场景(如相册中的电子票、截图中的条码)

3. 对焦模式

为适配不同扫描距离和场景,插件支持三种对焦模式:

  • 自动对焦:相机根据画面清晰度自动调整对焦,适用于扫描距离不固定的场景(默认模式)

  • 手动对焦:通过点击预览界面指定对焦区域,适用于条码较小或位于画面特定位置的场景

  • 连续对焦:相机持续保持对焦状态,适用于连续扫描多个条码的场景(如批量扫码入库)

4. 扫码API说明


cordova.plugins.barcodeScanner.scan(
    function (result) {
        if(result.cancelled) {
            return;
        }
        if(result.format != "QR_CODE") {
            alert("二维码不正确");
            return;
        }
        console.log(result.text);
    },
    function (error) {
        console.log("Scanning failed: " + error);
    }
);

许可证

本插件基于 Apache License 开源,详见 LICENSE 文件。

参考资源