Installation
Add carp_movesense_package to a CAMS app and configure Android and iOS.
Setting up the Movesense 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
carp_movesense_flutterplugin, which bundles the Movesense mobile library (MDS) for Android and iOS. There is no Movesense SDK to download.Note
If you upgrade from version 2.x of the package, remove the manual Movesense setup. On Android, delete the
android/libs/mdslib-*.aarfile and theflatDirrepository that points to it. On iOS, delete thepod 'Movesense'line inios/Podfile: keeping the pod links the library twice.If your code imports
package:carp_movesense_flutter/carp_movesense_flutter.dart, for example to scan for sensors withMds, also add the plugin as a direct dependency:Configure Android
The plugin and RxAndroidBle, the Bluetooth library that the Movesense library uses, add these permissions to your app's manifest:
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. You do not add any permissions yourself. On Android 12 or later, approximate location passes the CAMS check, unless your app declares
ACCESS_FINE_LOCATIONfor those versions; see Troubleshooting.The plugin needs
minSdk24 or later. Ifandroid/app/build.gradle.ktssets a lowerminSdk, raise it to 24.The bundled library contains native code for
arm64-v8a,armeabi-v7aandx86, but not forx86_64. Test on a physical phone, which Bluetooth needs anyway.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, and it terminates an app that uses Bluetooth without the key. The plugin starts Core Bluetooth when the app launches, so iOS may ask for Bluetooth access at the first launch.
The
bluetooth-centralmode keeps data from the sensor coming 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 plugin needs iOS 15.0 or later, the same minimum as CAMS. Run the app on an iPhone: the bundled library has no build for the simulator on Apple silicon Macs, and the simulator has no Bluetooth.
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
MovesenseSamplingPackagemakes the six measure types, theMovesenseDeviceconfiguration and its device manager known to CAMS. CAMS can then deploy protocols that use the sensor and read them from JSON, including protocols created with CAMS 1.x.configure()restores the studies saved on the phone, so the package must be registered before it runs.
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 device manager before connect(), and check that the participant allowed the nearby devices and location permissions. The log shows the message "has not the permissions required to connect".
If the app also declares ACCESS_FINE_LOCATION for Android 12 or later, the participant must allow precise location. With approximate location only, permission_handler reports the location permission as denied.
Declare ACCESS_FINE_LOCATION with tools:remove to drop the limit that the plugin sets:
Without tools:remove, the manifest merger copies the plugin's android:maxSdkVersion="30" onto your entry, so the app cannot get precise location on Android 12 or later.
Change the Runner target in ios/Podfile to static frameworks, which some CocoaPods setups need for the statically linked Movesense library:
Then run pod install in the ios/ folder.
Next step
Quickstart
Build an app that prints heart rate and ECG from a sensor.