更新记录
1.0.0(2026-09-22) 下载此版本
版本初始化
平台兼容性
uni-app(3.8.4)
| Vue2 | Vue2插件版本 | Vue3 | Vue3插件版本 | Chrome | Safari | app-vue | app-vue插件版本 | app-nvue | app-nvue插件版本 | Android | Android插件版本 | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | 1.0.0 | √ | 1.0.0 | × | × | √ | 1.0.0 | √ | 1.0.0 | 5.0 | 1.0.0 | × | × |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| × | × | × | × | × | × | × | × | × | × | × | × |
uni-app x(3.8.4)
| Chrome | Safari | Android | Android插件版本 | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|---|
| × | × | 5.0 | 1.0.0 | × | × | × |
思必拓扫码广播插件
一个用于 uni-app x / UTS Android 的扫码广播插件,适用于思必拓扫码。
功能特性
- 注册扫码结果广播接收器
- 可以手动触发扫码和停止扫码
- 获取扫码内容、原始字节数据和条码类型
- 支持注册 JavaScript / UTS 回调
- 支持销毁广播接收器,避免资源泄漏
适用场景(思必拓旧版本扫描广播)
本插件采用 Android 广播模式,不直接依赖具体扫描 SDK 的 Java API。设备上的扫描服务需要支持以下广播 Action 和 Extra Key:
| 用途 | Action / Key |
|---|---|
| 扫码结果广播 | com.se4500.onDecodeComplete |
| 开始扫码 | com.geomobile.se4500barcode |
| 停止扫码 | com.geomobile.se4500barcodestop |
| 条码内容 | se4500 |
| 条码字节数据 | se4500_byte |
| 条码类型 | se4500_type |
适用场景(思必拓新版本扫描广播)
自己手动修改源码,将上面旧版本的字段改为下面新版本的字段即可
| 用途 | Action / Key |
|---|---|
| 扫码结果广播 | com.spd.scan.ACTION_RESULT |
| 开始扫码 | com.geomobile.se4500barcode |
| 停止扫码 | com.geomobile.se4500barcodestop |
| 条码内容 | barcode |
| 条码字节数据 | barcode_byte |
| 条码类型 | barcode_type |
目录结构
uni_modules/
└── qz-sbt/
├── interface.uts
├── utssdk/
│ └── app-android/
│ └── index.uts
└── readme.md
接口说明
init()
初始化扫码管理器。
import { init } from '@/uni_modules/qz-sbt'
init()
建议在页面或应用初始化阶段调用一次。
onScanResult(callback)
注册扫码结果回调。
import { onScanResult } from '@/uni_modules/qz-sbt'
onScanResult((result) => {
console.log('扫码结果:', result.barcode)
console.log('字节数据:', result.barcodeByte)
console.log('条码类型:', result.barcodeType)
})
回调结果结构示例:
interface ScanResult {
barcode: string
barcodeByte: string
barcodeType: string
}
字段说明:
| 字段 | 类型 | 说明 |
|---|---|---|
barcode |
string |
扫描结果 |
barcodeByte |
string |
扫描结果原始数据 |
barcodeType |
string |
扫描结果类型 |
startScan()
开始扫描:
import { startScan } from '@/uni_modules/qz-sbt'
startScan()
通常可以将此方法绑定到页面按钮,如果使用实体扫描键则不需要调用。
stopScan()
停止扫码:
import { stopScan } from '@/uni_modules/qz-sbt'
stopScan()
通常可以将此方法绑定到页面按钮,如果使用实体扫描键则不需要调用。
destroy()
注销广播接收器并清理回调和 Context 引用:
import { destroy } from '@/uni_modules/qz-sbt'
destroy()
建议在页面销毁、功能退出或不再监听扫码结果时调用。
完整使用示例
<script lang="uts">
import {
init,
onScanResult,
startScan,
stopScan,
destroy
} from '@/uni_modules/qz-sbt'
export default {
data() {
return {
barcode: '',
barcodeByte: '',
barcodeType: ''
}
},
onLoad() {
// 1. 初始化广播接收器
init()
// 2. 注册扫码回调
onScanResult((result) => {
this.barcode = result.barcode
this.barcodeByte = result.barcodeByte
this.barcodeType = result.barcodeType
console.log('扫码内容:' + result.barcode)
console.log('扫码字节:' + result.barcodeByte)
console.log('条码类型:' + result.barcodeType)
})
},
onUnload() {
// 3. 页面退出时注销接收器
destroy()
},
methods: {
handleStartScan() {
startScan()
},
handleStopScan() {
stopScan()
}
}
}
</script>
<template>
<view>
<button @click="handleStartScan">
开始扫码
</button>
<button @click="handleStopScan">
停止扫码
</button>
<view>
<text>条码内容:{{ barcode }}</text>
<text>字节数据:{{ barcodeByte }}</text>
<text>条码类型:{{ barcodeType }}</text>
</view>
</view>
</template>
注意事项
1. 必须先初始化
调用 onScanResult() 前应先调用 init()。
推荐:
init()
onScanResult(callback)
2. 避免重复注册
插件内部通过 registered 标志防止重复注册广播接收器。
3. 避免重复设置回调
当前实现只保存一个回调:
private callback: ScanResultCallback | null = null
多次调用 onScanResult() 时,后一次回调会覆盖前一次回调。
4. 广播接收器生命周期
不再使用扫码功能时,请调用:
destroy()
否则可能造成广播接收器持续存在,或者在页面退出后继续触发回调。
版本说明
当前 README 根据以下实现编写:
- 平台:Android
- 技术:uni-app x / UTS
- 广播结果 Action:
com.se4500.onDecodeComplete - 开始扫码 Action:
com.geomobile.se4500barcode - 停止扫码 Action:
com.geomobile.se4500barcodestop - 结果字段:
se4500、se4500_byte、se4500_type

收藏人数:
下载插件并导入HBuilderX
赞赏(0)
下载 0
赞赏 0
下载 12627715
赞赏 1950
赞赏
京公网安备:11010802035340号