OpenEarable Flutter
This Dart package provides functionality for interacting with OpenEarable devices and some other wearables.
Try it online, provided your browser supports Web Bluetooth.
Permissions
For your app to be able to use UniversalBLE in this package, you need to grant the following permissions:
Android
You need to add the following permissions to your AndroidManifest.xml file:
<!-- flutter_reactive_ble permissions -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- location permissions -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
If you use location services in your app, remove android:maxSdkVersion="30" from the location permission tags
iOS / macOS
For iOS it is required you add the following entries to the Info.plist file of your app. It is not allowed to access Core BLuetooth without this. See our example app on how to implement this. For more indepth details: Blog post on iOS bluetooth permissions
iOS 13 and higher
- NSBluetoothAlwaysUsageDescription
iOS 12 and lower
- NSBluetoothPeripheralUsageDescription
For macOS, add the Bluetooth capability to the macOS app from Xcode.
Getting Started
To get started with the OpenEarable Flutter package, follow these steps:
1. Installation
Add the package to your flutter project: \
flutter pub add open_earable_flutter
Alternatively, you can follow the instructions on pub.flutter-io.cn
2. Import the package
import 'package:open_earable_flutter/open_earable_flutter.dart';
3. Initialize WearableManager
final WearableManager _wearableManager = WearableManager();
4. Scan for devices
_wearableManager.scanStream.listen((scannedDevice) {
// Handle scanned devices
});
_wearableManager.startScan();
5. Handle new connections
// Deal with new connected devices
_wearableManager.connectStream.listen((wearable) {
// Handle new wearable connection
wearable.addDisconnectListener(() {
// Handle disconnection
});
});
6. Connect to a device
Wearable wearable = await _wearableManager.connectToDevice(scannedDevice);
7. Access sensor data
In order to access sensor data, you need to check if the device is a SensorManager. Then you can access the sensor data streams by accessing the sensors property:
if (wearable is SensorManager) {
wearable.sensors.forEach((sensor) {
sensor.sensorStream.listen((data) {
// Handle sensor data
});
});
}
For more information about using sensor data, refer to the Using Sensor Data documentation.
For most devices, the sensors have to be configured before they start sending data. You can learn more about configuring sensors in the chapter Configuring Sensors.
Add custom Wearable Support
Learn more about how to add support for your own wearable devices in the Adding Custom Wearable Support documentation.