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.
You can install rn-bluetooth-classic
via npm or yarn:
npm install rn-bluetooth-classic
or
yarn add rn-bluetooth-classic
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.
npm install react-native-bluetooth-classic
or
yarn add react-native-bluetooth-classic
import { BluetoothProvider } from 'rn-bluetooth-classic';
const App = () => {
return (
<BluetoothProvider>
<YourApp />
</BluetoothProvider>
);
};
import { useBluetooth } from 'rn-bluetooth-classic';
const YourComponent = () => {
const { isScanning, devices, scanDevices, connectToDevice } = useBluetooth();
// Your component logic here...
};
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.
amitferman has released and maintains a with-rn-bluetooth-classic
Expo plugin to get things working.
You can install react-native-bluetooth-classic
and with-rn-bluetooth-classic
from npm using Expo's expo install
command:
expo install react-native-bluetooth-classic with-rn-bluetooth-classic
After installation, configure your app.json
or app.config.json
with the following settings:
{
"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.
- Request Bluetooth permissions
- Scan for nearby Bluetooth devices
- Connect to a Bluetooth device
- Receive data from connected devices
For a complete example of how to use rn-bluetooth-classic
, check out the example directory in this repository.
Contributions are welcome! Please open an issue or submit a pull request if you find any bugs or want to suggest improvements.
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.