react-native-bluetooth-datecs-printer
v1.1.0
Published
Module to printer in a Datecs bluetooth Printer
Downloads
62
Maintainers
Readme
clear# react-native-bluetooth-datecs-printer
Module to print on Datecs bluetooth printers.
✨ Now compatible with Expo SDK 54 and Android SDK 36!
📚 Documentation
- HOW_TO_TEST.md - 🧪 Como testar a biblioteca em outra aplicação
- TROUBLESHOOTING.md - ⚠️ Soluções para problemas comuns
- EXPO_SETUP.md - Complete Expo SDK 54 setup guide
- QUICK_START.md - Quick start in 5 minutes
- TESTING_GUIDE.md - Comprehensive testing guide
- examples/ExpoExample.tsx - Complete working example
Requirements
- React Native 0.76+
- React 18.3+
- Android SDK 36
- Android 8.0+ (API 26+)
- Expo SDK 54 (if using Expo)
Installation
npm install react-native-bluetooth-datecs-printer --saveor
yarn add react-native-bluetooth-datecs-printerSetup
For Expo Projects (SDK 54)
- Install
expo-build-properties:
npx expo install expo-build-properties- Configure
app.json:
{
"expo": {
"plugins": [
[
"expo-build-properties",
{
"android": {
"compileSdkVersion": 36,
"targetSdkVersion": 36,
"minSdkVersion": 26,
"buildToolsVersion": "35.0.0"
}
}
]
],
"android": {
"permissions": [
"BLUETOOTH",
"BLUETOOTH_ADMIN",
"BLUETOOTH_CONNECT",
"BLUETOOTH_SCAN",
"ACCESS_FINE_LOCATION",
"ACCESS_COARSE_LOCATION"
]
}
}
}- Run prebuild:
npx expo prebuild --clean- Run the app:
npx expo run:android⚠️ Note: This library does NOT work with Expo Go. You must use Expo Prebuild or Development Build.
For React Native CLI Projects
The library uses autolinking, so no manual linking is required for React Native 0.60+.
Android Permissions
Add to your android/app/src/main/AndroidManifest.xml:
<!-- Bluetooth permissions for Android 11 and below -->
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<!-- Bluetooth permissions for Android 12 and above -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
<!-- Location permissions (needed for Bluetooth scanning on Android 11 and below) -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />Usage
import { RNBluetoothDatecsPrinter } from 'react-native-bluetooth-datecs-printer';
import { PermissionsAndroid, Platform } from 'react-native';
// Request Bluetooth permissions (Android 12+)
async function requestBluetoothPermissions() {
if (Platform.OS === 'android' && Platform.Version >= 31) {
const granted = await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
]);
return (
granted['android.permission.BLUETOOTH_CONNECT'] === 'granted' &&
granted['android.permission.BLUETOOTH_SCAN'] === 'granted'
);
}
return true;
}
// Scan for paired devices
async function scanDevices() {
await requestBluetoothPermissions();
const devices = await RNBluetoothDatecsPrinter.getDeviceList();
console.log('Devices:', devices);
}
// Connect to a device
async function connect(deviceAddress) {
await RNBluetoothDatecsPrinter.connect(deviceAddress);
console.log('Connected!');
}
// Print text
async function print() {
await RNBluetoothDatecsPrinter.printText('Hello World!\n');
}
// Disconnect
async function disconnect() {
await RNBluetoothDatecsPrinter.disconnect();
}Complete Example
See examples/ExpoExample.tsx for a complete working example with UI.
API
Methods
getDeviceList(): Returns a list of paired Bluetooth devicesconnect(address: string): Connect to a device by MAC addressdisconnect(): Disconnect from the current deviceprintText(text: string): Print textprintQRCode(data: string, size?: number): Print QR codeprintBarcode(data: string, type?: number): Print barcodefeedPaper(lines?: number): Feed paper
Troubleshooting
Common Issues
- "Namespace not specified" error: Make sure you're using the latest version of the library
- Bluetooth permissions denied: Request runtime permissions on Android 12+
- Build fails: Clean the project with
./gradlew cleanornpx expo prebuild --clean - Printer not found: Make sure the printer is paired in Android Bluetooth settings
For more help, see EXPO_SETUP.md
Compatibility
| Package Version | Expo SDK | React Native | Android SDK | |----------------|----------|--------------|-------------| | 1.0.22+ | 54+ | 0.76+ | 36 | | < 1.0.22 | - | 0.72 | 30 |
License
MIT
