Installation
Add carp_esense_package to a CAMS app and configure Bluetooth on Android and iOS.
Setting up the eSense 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. It brings in the
esense_flutterplugin, which contains the eSense library for Android and uses theESenseCocoaPods pod on iOS.If your code imports
package:esense_flutter/esense.dart, for example to useESenseManager, also add the plugin as a direct dependency:Configure Android
Add the Bluetooth permissions that Android 12 or later requires to
android/app/src/main/AndroidManifest.xml, directly above the<application>element:android/app/src/main/AndroidManifest.xml BLUETOOTH_SCANlets the plugin find the earbud by its name, andneverForLocationdeclares that the app does not derive location from the scan.BLUETOOTH_CONNECTlets it connect to the earbud.The
esense_flutterplugin adds the rest to the merged manifest:BLUETOOTHandBLUETOOTH_ADMIN, the Bluetooth permissions of Android 11 and earlier;ACCESS_FINE_LOCATIONandACCESS_COARSE_LOCATION, because CAMS checks the location permission on every Android version before it connects to a Bluetooth device;- the
android.hardware.bluetooth_lefeature as required, so Google Play offers the app only to phones with Bluetooth Low Energy.
Because the plugin declares
ACCESS_FINE_LOCATION, the participant must allow precise location on Android 12 or later. With approximate location only,permission_handlerreports the location permission as denied, and CAMS does not connect to the earbud.Warning
If your manifest declares the location permissions itself, do not limit them with
android:maxSdkVersion. CAMS needs the location permission on every Android version.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 earbud, and the data, flowing while the app is in the background. In Xcode, it is Uses Bluetooth LE accessories under Signing & Capabilities → Background Modes.The package acts only as a Bluetooth central, which scans for the earbud and connects to it, so it needs no other background mode.
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.esense_flutteris available only as a CocoaPods pod, so the iOS project keeps its Podfile. If the project uses Swift Package Manager, Flutter still installs this plugin with CocoaPods. The plugin needs iOS 10.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.The library is
esense.dart, notcarp_esense_package.dart. Registering makes the two eSense measure types and theESenseDeviceconfiguration known to CAMS, and adds theESenseDeviceManagerthat connects to the earbud. It also registers the eSense 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 eSense device manager before it connects, because neither CAMS nor the plugin asks for Bluetooth permissions by itself. On Android, also check that the merged manifest declares both location permissions without android:maxSdkVersion. On Android 12 or later, the participant must allow precise location.
Next step
Quickstart
Connect to an eSense earbud and print its button and motion events.