rn-pda-broadcast-scanner
v1.0.2
Published
Bridge to use the PDA broadcast scanner
Downloads
3
Readme
rn-pda-broadcast-scanner
react-native 版本为7.x
Getting started
$ npm install rn-pda-broadcast-scanner --save
安装后处理
android/settings.gradle
文件追加下面内容:
include ':rn-pda-broadcast-scanner'
project(':rn-pda-broadcast-scanner').projectDir = new File(rootProject.projectDir, '../node_modules/rn-pda-broadcast-scanner/android')
android/app/src/main/java/com/q3c_erp_app_shell/MainApplication.java
文件追加引用
import com.broadcast.ScancodePackage;
Usage
// TODO: What to do with the module?
import { NativeModules } from "react-native";
const { ScanCode } = NativeModules;
//设置扫码选项(当PDA设备能通过广播进行设置的时候可用)
//设置扫码选项(当PDA设备能通过广播进行设置的时候可用)
ScanCode.setBroadcastSetting('com.android.scanner.service_settings', [
{
key: 'barcode_send_mode',
value: 'BROADCAST',
},
]);
//广播和接收字段(接收的广播名和接收的字段名)
ScanCode.getCode('com.honeywell.scan.broadcast', 'data');
//接收扫描结果
import { DeviceEventEmitter } from "react-native";
componentWillMount()
{
if (this.searchListener) {
this.searchListener.remove();
}
this.searchListener = DeviceEventEmitter.addListener("scannerCodeShow", e => {
console.log(e.code)
}
)
}
//退出页面移除监听
componentWillUnmount()
{
if (this.searchListener) {
DeviceEventEmitter.removeListener("scannerCodeShow");
this.searchListener.remove();
this.searchListener = null;
}
}