A React Native library for integrating Newland barcode scanners with Android devices.
npm install react-native-newland- Add the package to your React Native project's
MainApplication.java:
import nl.kega.newland.NewlandPackage;
// In the getPackages() method:
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new NewlandPackage() // Add this line
);
}- Add permissions to your
android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />import React, { useEffect, useState } from 'react';
import { BarcodeScanner } from 'react-native-newland';
const App = () => {
const [scannedData, setScannedData] = useState(null);
useEffect(() => {
// Enable the scanner
BarcodeScanner.enable();
// Listen for barcode scan events
const subscription = BarcodeScanner.onBarcode((data) => {
console.log('Barcode scanned:', data);
setScannedData(data);
});
// Cleanup on unmount
return () => {
subscription.remove();
BarcodeScanner.release();
};
}, []);
const handleScan = () => {
BarcodeScanner.read();
};
return (
// Your UI here
);
};Enables the barcode scanner and registers broadcast receivers.
Disables the barcode scanner and unregisters broadcast receivers.
Triggers a barcode scan operation.
Parameters:
config(optional): Configuration object for the scan operation
Releases all resources and unregisters receivers. Call this when you're done using the scanner.
Listens for successful barcode scan events.
Callback Parameters:
data.data: The scanned barcode datadata.type: The barcode type name (e.g., "QR Code", "Code128", "EAN13")data.typeId: The numeric barcode type ID from Newland symbology mappingdata.category: The barcode category (e.g., "2D Matrix", "1D Linear", "Postal")data.status: The scan status from the devicedata.timestamp: Timestamp when the barcode was scanned
Supported Barcode Types: The library supports all major barcode symbologies including:
- 1D Barcodes: Code128, Code39, Code93, UPC-A, UPC-E, EAN-13, EAN-8, Codabar, Interleaved 2 of 5, MSI, Code11
- 2D Barcodes: QR Code, Data Matrix, PDF417, Aztec, MaxiCode
- Postal Codes: POSTNET, Planet, Australian Post, UK Post, Japan Post
- Composite Codes: RSS-14, RSS Limited, RSS Expanded
- Healthcare: HIBC variants of major symbologies
- And many more (see source code for complete mapping)
Returns: Subscription object with a remove() method
Listens for multiple barcode scan events (if supported).
Listens for status events from the scanner.
This library is designed to work with Newland Android PDA devices that support the following intent actions:
nlscan.action.SCANNER_RESULT- For receiving scan resultsnlscan.action.SCANNER_TRIG- For triggering scans
- Newland MT90 series
- Newland MT65 series
- Newland MT30 series
- Other Newland Android PDA devices with barcode scanning capabilities
- Check Permissions: Ensure camera and other required permissions are granted
- Device Compatibility: Verify you're running on a Newland device
- Enable Scanner: Make sure to call
BarcodeScanner.enable()before scanning - Check Logs: Look for debug messages with tag "BarcodeModule"
- Event Listeners: Ensure you've set up the
onBarcodeevent listener - Scanner State: Check that the scanner is enabled
- Broadcast Intents: Verify the device supports Newland broadcast intents
See the example directory for a complete working example.
ISC
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.