A React Native Bluetooth provider using react-native-bluetooth-classic
npm install rn-bluetooth-classic
---
rn-bluetooth-classic is a React Native package that provides a Bluetooth context and hooks for managing Bluetooth functionality in your app. It handles permissions, device scanning, connection management, and data reception.
rn-bluetooth-classic via npm or yarn:
bash
npm install rn-bluetooth-classic
`
or
`bash
yarn add rn-bluetooth-classic
`
Dependencies
rn-bluetooth-classic uses react-native-bluetooth-classic under the hood to scan and connect to devices and only acts as a wrapper on top to make it easier to use.
`bash
npm install react-native-bluetooth-classic
`
or
`bash
yarn add react-native-bluetooth-classic
`
Usage
$3
`javascript
import { BluetoothProvider } from 'rn-bluetooth-classic';
const App = () => {
return (
);
};
`
$3
`javascript
import { useBluetooth } from 'rn-bluetooth-classic';
const YourComponent = () => {
const { isScanning, devices, scanDevices, connectToDevice } = useBluetooth();
// Your component logic here...
};
`
Use with Expo
If you are using Expo and want to integrate rn-bluetooth-classic, you can use the with-rn-bluetooth-classic Expo plugin maintained by amitferman. This plugin helps with auto-configuration of permissions and protocols.
$3
amitferman has released and maintains a with-rn-bluetooth-classic Expo plugin to get things working.
- with-rn-bluetooth-classic GitHub Repository
$3
You can install react-native-bluetooth-classic and with-rn-bluetooth-classic from npm using Expo's expo install command:
`bash
expo install react-native-bluetooth-classic with-rn-bluetooth-classic
`
$3
After installation, configure your app.json or app.config.json with the following settings:
`json
{
"plugins": [
["with-rn-bluetooth-classic",
{
"peripheralUsageDescription": "Allow myDevice to check bluetooth peripheral info",
"alwaysUsageDescription": "Allow myDevice to always use bluetooth info",
"protocols": [
"com.myCompany.p1",
"com.myCompany.p2"
]
}
]
]
}
`
Make sure to replace "com.myCompany.p1" and "com.myCompany.p2" with your own protocol identifiers.
Features
- Request Bluetooth permissions
- Scan for nearby Bluetooth devices
- Connect to a Bluetooth device
- Receive data from connected devices
Example
For a complete example of how to use rn-bluetooth-classic, check out the example directory in this repository.
Contributing
Contributions are welcome! Please open an issue or submit a pull request if you find any bugs or want to suggest improvements.
License
This package is licensed under the MIT License. See the LICENSE file for details.
---
Feel free to customize this template with additional information specific to your package. Make sure to replace placeholders like YourApp` with actual names or values.