Installation
Add carp_polar_package to a CAMS app and configure Bluetooth on Android and iOS.
Setting up the Polar package takes four steps on top of the CARP Mobile Sensing (CAMS) setup:
Add the packages
The package needs CAMS, so complete Installation for CAMS first.
The package brings in the
polarplugin, which adds the Polar BLE SDK to the Android and iOS builds. With CAMS 2.5.1,flutter pub addresolvespolar7.11.0 on Flutter 3.44 or later and 7.10.1 on earlier versions. Both include Polar BLE SDK 6.14.0.If your code imports
package:polar/polar.dart, for example to usePolarDataType, also add the plugin as a direct dependency:Configure Android
Add the Bluetooth and location permissions to
android/app/src/main/AndroidManifest.xml, directly above the<application>element:android/app/src/main/AndroidManifest.xml The permissions serve these purposes:
Permission Purpose BLUETOOTH_SCANLets the Polar BLE SDK find the sensor on Android 12 or later. neverForLocationdeclares that the app does not derive location from the scan.BLUETOOTH_CONNECTLets the Polar BLE SDK connect to the sensor on Android 12 or later. ACCESS_FINE_LOCATION,ACCESS_COARSE_LOCATIONCAMS checks the location permission on every Android version before it connects to a Bluetooth device. Warning
Do not limit the location permissions with
android:maxSdkVersion. CAMS needs the location permission on every Android version.The
polarplugin adds the legacyBLUETOOTHandBLUETOOTH_ADMINpermissions for Android 11 and earlier to the merged manifest. The Polar BLE SDK needsminSdk24 or later, the default for new Flutter projects. The plugin downloads the SDK from the JitPack Maven repository.Configure iOS
Add a Bluetooth usage description and the
bluetooth-centralbackground mode toios/Runner/Info.plist, inside the<dict>:ios/Runner/Info.plist If
UIBackgroundModesalready exists, add thebluetooth-centralstring to it. The background mode keeps the connection to the sensor, and the data, flowing while the app is in the background. In Xcode, it is Uses Bluetooth LE accessories under Signing & Capabilities → Background Modes.CAMS requests the Bluetooth permission through the
permission_handlerplugin. If your iOS project uses CocoaPods, enable that permission in thepost_installblock ofios/Podfile:ios/Podfile If the list already exists, add only the
PERMISSION_BLUETOOTH=1line. With Swift Package Manager,permission_handlerenables the permission by itself whenInfo.plistcontainsNSBluetoothAlwaysUsageDescription.The
polarplugin supports both CocoaPods and Swift Package Manager, and it pulls in the Polar BLE SDK either way. Do not addPolarBleSdkto the project yourself. The SDK needs iOS 14.0 or later, which the CAMS minimum of 15.0 covers.Register the sampling package
Register the package in
main(), before you configureSmartPhoneClientManager:Call
CarpMobileSensing.ensureInitialized()beforeregister(): registering a sampling package before CAMS is initialized throws a null check error.Registering makes the seven Polar measure types and the
PolarDeviceconfiguration known to CAMS, and adds thePolarDeviceManagerthat connects to the sensor. It also registers the Polar classes for JSON, so that CAMS can read protocols and data that contain them.
Troubleshooting
Hide Smartphone when you import carp_core. Both carp_core and carp_mobile_sensing define the class, and CAMS apps use the one in carp_mobile_sensing:
Call requestPermissions() on the Polar device manager before it connects, because CAMS does not ask for Bluetooth permissions by itself. On Android, also check that the manifest declares both location permissions without android:maxSdkVersion. See Request Bluetooth permissions.
Next step
Quickstart
Connect to a Polar sensor and print its heart rate and ECG.