更新记录
v1.0.1(2024-09-19) 下载此版本
- 插件兼容性升级 根据平台要求,插件更新到Android 14 (API 34)版本,现已支持HBuidlerX 4.26-alpha平台云端打包。
v1.0.0(2024-07-05) 下载此版本
UNIPHIZ设备二维码扫描插件
平台兼容性
Android | Android CPU类型 | iOS |
---|---|---|
适用版本区间:5.0 - 14.0 | armeabi-v7a:支持,arm64-v8a:支持,x86:未测试 | × |
原生插件通用使用流程:
- 购买插件,选择该插件绑定的项目。
- 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
- 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
- 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
- 开发完毕后正式云打包
付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios
注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择
UNIPHIZ-API-Scanner Specification
To use this plugin, you also need to install the UNIPHIZ-API-Common plugin, otherwise some functions may not work properly.
UNIPHIZ-API-Scanner provides users with functions such as scanner management, setup and scanning of QR codes, etc.
Environment
CompileSdkVersion 34
MinSdkVersion 21
TargetSdkVersion 34
Build Gradle JDK Version JDK-21.0.2
Source Compatibility JDK-1.8
Gradle Version gradle-8.7-bin
Android Gradle Plugin Version
Getting started
Open the sample project using HBuilderX 4.26-alpha.
How to use the plugins
- Recognize the name of the plugin's module.
Open the file pathed in ./nativeplugins/<plugin_name>/package.json
, the plugin is described by the value of _dp_nativeplugin -> android -> plugins
.
- Get instance of the plugin's module in the page files.
Use uni.requireNativePlugin(<module_name>)
to get instance of the module.
- Call the function of the instance.
Project structure
/nativeplugins
The folder named nativeplugins
contains native plugins and their specification files.
Each native plugin has one folder.
/pages
The folder named pages
contains page files in vue format.
/unpackage
The folder named unpackage
contains files generated by HBuilderX.
manifest.json
The file named manifest.json
contains the application configuration.
Custom Plugins
- Plugin description
Create folder ./nativeplugins/<plugin_name>/android
in the root path firstly, and move the plugin file in AAR format to ./nativeplugins/<plugin_name>/android
.
Then create the description file ./nativeplugins/<plugin_name>/package.json
in the project root path, and fill in the content according to the sample project.
- Select local plugins
Each value of the key named of _dp_nativeplugin -> android -> plugins -> name
must start with <plugin_name>
firstly, then make sure value of the version
key corresponds to the file in AAR format.
If the files in the nativeplugins directory are configured correctly, they will be listed in the app-plus -> nativePlugins
section of the manifest.json
file.
Finally open the manifest.json
file in the project root path, and check the native plugins -> local plugins
.
- Genarate Custom Playground
Modify versionCode
to make it larger than the current value, change versionName
to make it matches versionCode
, and make sure to modify versionCode
and versionName
before each packaging.
Then click Run -> Mobile App Playground -> Generate Custom Playground
, choose Customize playground native runner -> Standard Mode(upload code and certificate, DCloud promises not to keep)
.
Wait for packaging to complete.
- Run the program
Use USB cable to connect your device, then click Run -> Mobile App Playground -> Android Run
.
Choose the connected device and then click Operating with custom playground -> run
.
Interface Specification
Import
const scanner = uni.requireNativePlugin("UNIPHIZ-API-Scanner-ScannerManager")
Usage
1. init()
Initializes the ScannerManager.
Return:
- JSON object of result
- code - code of result
- message - message of result
- data - data of result
2. openScan()
Opens the scanner.
Note:
- Call this method to open the scanner and use
closeScan()
to close it. - Call
closeScan()
when the activity is finished.
Return:
- JSON object of result
- code - code of result
- message - message of result
- data - true: Open succeeded; false: Failed to open
3. closeScan()
Closes the scanner.
Return:
- JSON object of result
- code - code of result
- message - message of result
- data - true: Indicates success; false: Indicates failure
4. setBatchScanMode(maxScanItem: number)
Sets the maximum number of scans to be performed in batch scanning mode.
Parameters:
- maxScanItem (number) - The maximum number of scans performed.
- If the parameter is 0, the scanner will perform continuous scanning.
- If the parameter is less than 0, batch scanning mode cannot be used.
Return:
- JSON object of result
- code - code of result
- message - message of result
- data - true: success; false: failed
5. startScan(onRead: callback, onComplete: callback, onCancel: callback)
Starts scanning and provides callback functions for when the scan completes, is cancelled, and when a barcode is read.
Parameters:
- onRead (callback) - A callback function that will be invoked after a barcode is read. The result will be a JSON object containing the
content
,class
, andformat
of the barcode. - onComplete (callback) - A callback function that will be invoked when the scan just ends.
- onCancel (callback) - A callback function that will be invoked when the scan is cancelled.
Return:
- JSON object of result
- code - code of result
- message - message of result
- data - true: success; false: failed
6. stopScan()
Stops scanning.
Return:
- JSON object of result
- code - code of result
- message - message of result
- data - true: success; false: failed
7. setBarcodeParam(paramStr: string)
Sets the barcode device parameters.
Parameters:
- paramStr (string) - The device parameters, represented as key-value pairs separated by commas:
- The key represents the format of the barcode.
- The value indicates whether the device supports that format.
- eg:
UPC-A,true,C39,true,C128,falseI25,true,C93,false,GS1 DATABAR,true,MSI,false,CODEBLOCK F,false,PDF417,true
Return:
- JSON object of result
- code - code of result
- message - message of result
- data - true: success; false: failed
8. getBarcodeParam()
Retrieves the barcode device parameters.
Return:
- JSON object of result
- code - code of result
- message - message of result
- data - a map of the device parameters
9. setFlashOn(isOn: boolean)
Enables or disables the flashlight during scanning.
Parameters:
- isOn (boolean) - true: enable; false: disable
Return:
- JSON object of result
- code - code of result
- message - message of result
- data - true: success; false: failed
10. destroy()
Releases the ScannerManager resources and closes the scanner.
Return:
- None
Sample
const scanner = uni.requireNativePlugin("UNIPHIZ-API-Scanner-ScannerManager")
scanner.init()
scanner.openScan()
scanner.startScan(result => {
console.log(result)
do something after scan completed
}, () => {
do something when scan completed
}, () => {
do something when scan cancel
})
scanner.stopScan()
scanner.closeScan()