react-native-uhf
v1.3.4
Published
## Getting started
Downloads
4
Readme
react-native-uhf
Getting started
$ npm install react-native-uhf --save
Mostly automatic installation
$ react-native link react-native-uhf
Manual installation
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNReactNativeUhfPackage;
to the imports at the top of the file - Add
new RNReactNativeUhfPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-uhf' project(':react-native-uhf').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-uhf/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-uhf')
Example
import React, {Component} from 'react';
import {
DeviceEventEmitter,
PermissionsAndroid,
ScrollView,
View,
Text,
StatusBar,
Button,
Alert,
} from 'react-native';
import RNReactNativeUhf from 'react-native-uhf';
class App extends Component {
componentDidMount() {
this.startUhfListener();
}
startUhfListener() {
RNReactNativeUhf.startUhfService();
DeviceEventEmitter.addListener(
'onReadDataScanner',
this.onReadDataScanner,
this
);
DeviceEventEmitter.addListener(
'onReadDataConnect',
this.onReadDataConnect,
this
);
DeviceEventEmitter.addListener(
'onReadDataInventory',
this.onReadDataInventory,
this
);
}
onReadDataScanner(data) {
console.log('onReadDataScanner', data);
}
onReadDataConnect(data) {
console.log('onReadDataConnect', data);
}
onReadDataInventory(data) {
console.log('onReadDataInventory', data);
}
showBluetoothDevice() {
RNReactNativeUhf.showBluetoothDevice();
}
connect() {
RNReactNativeUhf.connect("C0:44:82:B6:20:6E");
}
disconnect() {
RNReactNativeUhf.disconnect();
}
inventory() {
RNReactNativeUhf.getInventory();
}
inventoryLoop() {
RNReactNativeUhf.getInventoryLoop();
}
inventoryLoopStop() {
RNReactNativeUhf.stopInventoryLoop();
}
clearInventory() {
RNReactNativeUhf.clearInventory();
}
setScanned() {
RNReactNativeUhf.setInventory(true);
}
render() {
return (
<View>
<Button onPress={this.showBluetoothDevice} title="showBluetoothDevice" />
<Button onPress={this.connect} title="connect" />
<Button onPress={this.disconnect} title="disconnect" />
<Button onPress={this.inventory} title="inventory" />
<Button onPress={this.inventoryLoop} title="inventoryLoop" />
<Button onPress={this.inventoryLoopStop} title="inventoryLoopStop" />
<Button onPress={this.clearInventory} title="clearInventory" />
<Button onPress={this.setScanned} title="setScanned" />
</View>
);
}
}
export default App;