Installation
Add carp_movisens_package to a CAMS app and configure Bluetooth on Android and iOS.
Setting up the Movisens 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
movisens_flutterandflutter_blue_plusplugins. They talk to the sensor directly over Bluetooth Low Energy (BLE), so there is no Movisens SDK to install.Configure Android
flutter_blue_plusdeclares no permissions, so that each app chooses its own. Add these entries toandroid/app/src/main/AndroidManifest.xml, directly above the<application>element:android/app/src/main/AndroidManifest.xml The permissions serve these purposes:
Permission Android versions Purpose BLUETOOTH_SCAN12 or later Find the sensor. The neverForLocationflag tells Android that the app does not derive location from scans.BLUETOOTH_CONNECT12 or later Connect to the sensor. BLUETOOTH,BLUETOOTH_ADMIN11 and lower Use Bluetooth before Android 12. ACCESS_FINE_LOCATION11 and lower Get scan results before Android 12. ACCESS_COARSE_LOCATIONAll Pass the location check that CAMS makes before it connects a Bluetooth device, on every Android version. Keep
android:maxSdkVersion="30"onACCESS_FINE_LOCATION. If the app also declares it for Android 12 or later, the participant must allow precise location. With approximate location only,permission_handlerreports the location permission as denied, and CAMS does not connect.The
uses-featureentry tells Google Play that the app uses BLE but does not require it. Setandroid:required="true"to offer the app only to phones with BLE.flutter_blue_plusneedsminSdk21 or later, which is lower than CAMS needs, soandroid/app/build.gradle.ktsneeds no change.Configure iOS
Add the Bluetooth usage description and the
bluetooth-centralbackground mode toios/Runner/Info.plist, inside the top-level<dict>:ios/Runner/Info.plist iOS shows the text in its Bluetooth permission dialog the first time the app uses Bluetooth. It terminates an app that uses Bluetooth without the key.
The
bluetooth-centralmode lets iOS deliver data from the sensor while the app is in the background. In Xcode, it is Uses Bluetooth LE accessories under Signing & Capabilities → Background Modes. IfUIBackgroundModesalready exists, addbluetooth-centralto its array.The package needs no other keys and works with the CAMS minimum of iOS 15.0.
Note
With CocoaPods,
permission_handlerreports the Bluetooth permission as denied without asking, unlessios/PodfiledefinesPERMISSION_BLUETOOTH=1. CAMS does not check this permission on iOS, so the macro is optional.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
MovisensSamplingPackagemakes the six measure types, theMovisensDeviceconfiguration and its device manager known to CAMS. CAMS can then read protocols that contain the sensor, including protocols created with CAMS 1.x.configure()restores the studies saved on the phone, so the package must be registered before it runs.Registering also adds heart rate and step count transformers to the Open mHealth (OMH) format of CAMS. For the Fast Healthcare Interoperability Resources (FHIR) format, it adds a heart rate transformer.
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:
Check that the manifest declares ACCESS_COARSE_LOCATION without android:maxSdkVersion, and call requestPermissions() on the device manager before connect(). The log shows the message "has not the permissions required to connect".
If the app declares ACCESS_FINE_LOCATION for Android 12 or later, the participant must allow precise location, not approximate location.
Ask the participant to turn on location in the phone's settings. On Android 11 or lower, flutter_blue_plus scans only while location is on, and otherwise it reports "Location services are required for Bluetooth scan". Android 12 and later do not need it.
Keep the classes of flutter_blue_plus in release builds. Add this line to android/app/proguard-rules.pro:
Without it, scans in release builds fail with PlatformException(startScan, Field androidScanMode_ ... not found.
If another package in your app requires flutter_blue_plus 2.x, use a version of that package that works with 1.x. movisens_flutter requires flutter_blue_plus ^1.29.1, so flutter pub get cannot resolve the dependencies otherwise.
Next step
Quickstart
Build an app that prints tap markers and skin temperature.