react-native-scancode
Getting started
$ npm install react-native-scancode --save
Mostly automatic installation
$ react-native link react-native-scancode
Manual installation
Android
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.xiaomo.ScancodePackage;
to the imports at the top of the file - Add
new ScancodePackage()
to the list returned by the getPackages()
method
-
Append the following lines to android/settings.gradle
:
include ':react-native-scancode'
project(':react-native-scancode').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-scancode/android')
-
Insert the following lines inside the dependencies block in android/app/build.gradle
:
compile project(':react-native-scancode')
Usage
import { NativeModules } from "react-native";
const { WmsScanCode } = NativeModules;
let obj={};
let list=[];
obj['key']='barcode_send_mode';
obj['value']='BROADCAST';
list.push(obj);
WmsScanCode.setBroadcastSetting('com.android.scanner.service_settings',list);
WmsScanCode.getCode('android.intent.action.SCANRESULT','value');
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;
}
}