rn-honeywell-reader
v1.0.2
Published
A barcode reader for Honeywell handheld devices like Honeywell EDA50K (tested)
Downloads
3
Readme
React Native Honeywell Barcode Reader
This package works with Honeywell devices that have an integrated barcode scanner, like the Honeywell EDA50K (tested).
Actually, I custom from https://github.com/Volst/react-native-honeywell-scanner but fix cannot remove event listener (even you close the reader). And if you don't remove, the event will fire twice, triple... more and more times when you call addListener
until you kill the app.
The bug at here is you can not remove event listener by call DeviceEventEmitter.removeListener(eventName, handler)
since it doesn't have this method. Follow here: https://stackoverflow.com/questions/36886628/how-do-you-remove-a-listener-from-react-natives-eventemitter-instance
Installation
npm i rn-honeywell-reader
Link automatically:
react-native link rn-honeywell-reader
Link manually (recommend):
- In
app\build.gradle
add
compile project(':rn-honeywell-reader')
- In
settings.gradle
add
include ':rn-honeywell-reader'
project(':rn-honeywell-reader').projectDir = new File(rootProject.projectDir, '../node_modules/rn-honeywell-reader/android')
- In
MainApplication.java
Add this line to import package
import com.honeywell.reader.HoneywellBarcodeReaderPackage;
and add this line to getPackages()
new HoneywellBarcodeReaderPackage()
Usage
First you'll want to check whether the device is a Honeywell scanner:
import HoneywellBarcodeReader from "rn-honeywell-reader";
HoneywellBarcodeReader.isCompatible; // true or false
The barcode reader needs to be "claimed" by your application; meanwhile no other application can use it. You can do that like this:
HoneywellBarcodeReader.startReader().then((claimed) => {
console.log(claimed ? "Barcode reader is claimed" : "Barcode reader is busy");
});
To get events from the barcode scanner:
HoneywellBarcodeReader.onBarcodeReadSuccess((event) => {
console.log("Received data", event);
});
HoneywellBarcodeReader.onBarcodeReadFail(() => {
console.log("Barcode read failed");
});
To free the claim and stop the reader, also freeing up resources:
HoneywellBarcodeReader.stopReader().then(() => {
console.log("Freedom!");
});
To stop receiving events:
HoneywellBarcodeReader.offBarcodeReadSuccess();
HoneywellBarcodeReader.offBarcodeReadFail();