react-native-brother-print-android
v1.0.0
Published
React Native module for Brother Print SDK - Android only
Downloads
31
Maintainers
Readme
react-native-brother-print
React Native module for Brother Print SDK - Android only. This module provides silent printing capabilities for Brother printers without showing system print dialogs.
Features
- Silent printing - Print text directly without user interaction
- Printer discovery - Find Brother printers on WiFi, Bluetooth, and USB
- Connection management - Connect and disconnect from printers
- Status checking - Monitor printer status and battery level
- Configurable printing - Font size, alignment, copies, and more
- TypeScript support - Full type definitions included
- Promise-based APIs - Modern async/await support
Supported Platforms
- ✅ Android (API 21+)
- ❌ iOS (not supported - Android only)
Installation
npm install react-native-brother-printAndroid Setup
Copy the Brother SDK AAR file to your Android project:
cp node_modules/react-native-brother-print/android/libs/BrotherPrintLibrary.aar android/app/libs/Add the module to your
MainApplication.java:import com.brotherprint.BrotherPrintPackage; @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), new BrotherPrintPackage() // Add this line ); }Add required permissions to your
AndroidManifest.xml:<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />Request runtime permissions in your app:
import { PermissionsAndroid, Platform } from 'react-native'; if (Platform.OS === 'android') { await PermissionsAndroid.requestMultiple([ PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN, PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT, ]); }
Usage
import BrotherPrintModule from 'react-native-brother-print';
// Search for printers
const printers = await BrotherPrintModule.searchPrinters(15000);
// Connect to a printer
const connected = await BrotherPrintModule.connectPrinter(printers[0]);
// Print text with options
const options = {
fontSize: 12,
fontBold: false,
alignment: 'center',
copies: 1,
cutAtEnd: true,
autoCut: true,
};
const success = await BrotherPrintModule.printText('Hello World!', options);
// Check printer status
const status = await BrotherPrintModule.getPrinterStatus();
// Disconnect
await BrotherPrintModule.disconnect();API Reference
Methods
searchPrinters(timeoutMs?: number): Promise<PrinterInfo[]>
Discover available Brother printers on the network.
timeoutMs- Search timeout in milliseconds (default: 15000)- Returns array of
PrinterInfoobjects
connectPrinter(printerInfo: PrinterInfo): Promise<boolean>
Connect to a specific printer.
printerInfo- Printer information from search results- Returns
trueif connection successful
printText(text: string, options?: PrintOptions): Promise<boolean>
Print text to the connected printer.
text- Text to print (supports\\nfor line breaks)options- Print configuration options- Returns
trueif print successful
getPrinterStatus(): Promise<PrinterStatus>
Get the current status of the connected printer.
- Returns
PrinterStatusobject with error info and battery status
disconnect(): Promise<boolean>
Disconnect from the current printer.
- Returns
trueif disconnect successful
Types
PrinterInfo
interface PrinterInfo {
id: string;
modelName: string;
ipAddress?: string;
macAddress?: string;
serialNumber?: string;
nodeName?: string;
location?: string;
channelType: 'WiFi' | 'Bluetooth' | 'BluetoothLE' | 'USB';
}PrintOptions
interface PrintOptions {
fontSize?: number; // Font size (default: 12)
fontBold?: boolean; // Bold text (default: false)
alignment?: 'left' | 'center' | 'right'; // Text alignment (default: 'left')
copies?: number; // Number of copies (default: 1)
cutAtEnd?: boolean; // Cut paper at end (default: true)
autoCut?: boolean; // Auto cut paper (default: true)
}PrinterStatus
interface PrinterStatus {
isOnline: boolean;
errorStatus: string[];
mediaType?: string;
mediaSize?: string;
batteryLevel?: number;
batteryStatus?: 'Full' | 'Half' | 'Low' | 'Replace' | 'Unknown';
}Example App
The package includes a complete example app demonstrating all features:
- Printer discovery
- Connection management
- Text printing with configurable options
- Status checking
- Error handling
To run the example:
cd example
npm install
npx react-native run-androidSupported Brother Printers
This module supports Brother printers compatible with the Brother Mobile SDK, including:
- P-touch series - Label printers
- QL series - Label printers
- PocketJet series - Mobile printers
- MW series - Mobile printers
- RJ series - Mobile printers
- TD series - Desktop printers
Error Handling
All methods return promises that reject with descriptive error messages:
try {
const printers = await BrotherPrintModule.searchPrinters();
} catch (error) {
console.error('Search failed:', error.message);
// Handle specific error codes
if (error.code === 'BLUETOOTH_ERROR') {
// Handle Bluetooth issues
}
}Troubleshooting
Printer Discovery Issues
- Ensure printer and device are on the same WiFi network
- Check that the printer is powered on and not in sleep mode
- Verify all required permissions are granted
- For Bluetooth printers, make sure Bluetooth is enabled
Connection Problems
- Verify printer is not connected to another device
- Check network connectivity
- Ensure printer model is supported
- Try power cycling the printer
Print Failures
- Check printer paper and ink/toner levels
- Verify printer is online and ready
- Ensure text formatting is correct
- Check for printer error conditions
License
MIT
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Support
For issues and questions:
- Check the troubleshooting section
- Review the example app
- Open an issue on GitHub
