Installation
Add carp_context_package to a CAMS app and configure Android and iOS.
Adding the package to a CARP Mobile Sensing (CAMS) app takes four steps:
Add the packages
The package runs on CAMS, so complete the CAMS setup in Installation first. The steps below add only what this package needs on top of it.
Configure Android
The
activity_recognition_flutterplugin requires API level 26 (Android 8.0), which is higher than theflutter.minSdkVersiondefault. SetminSdkto 26 or later:android/app/build.gradle.kts Add the background location and internet permissions to
android/app/src/main/AndroidManifest.xml:android/app/src/main/AndroidManifest.xml ACCESS_BACKGROUND_LOCATIONlets the participant allow location all the time; without it,LOCATION,GEOFENCEandMOBILITYcollect nothing on Android 10 and later.WEATHERandAIR_QUALITYneedINTERNETin release builds, because Flutter declares it only in the debug and profile manifests.Permissions that the plugins add The plugins merge these entries into your app's manifest, so you do not add them yourself:
Plugin Merged permissions and components locationACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION,FOREGROUND_SERVICE,FOREGROUND_SERVICE_LOCATIONand a foreground service of typelocationactivity_recognition_flutterACTIVITY_RECOGNITION,com.google.android.gms.permission.ACTIVITY_RECOGNITION,FOREGROUND_SERVICE,FOREGROUND_SERVICE_HEALTH, a broadcast receiver and a foreground service of typehealthConfigure iOS
Add the location usage descriptions and the
locationbackground mode toios/Runner/Info.plist, inside the top-level<dict>:ios/Runner/Info.plist iOS shows the two texts in its location prompts. The
locationbackground mode lets the app receive locations in the background; in Xcode, it is Location updates under Signing & Capabilities → Background Modes. IfUIBackgroundModesalready exists, addlocationto its array.ACTIVITYalso needs theNSMotionUsageDescriptionkey from the CAMS setup. The package needs iOS 15.0 or later, the same minimum as CAMS.The
activity_recognition_flutterplugin ships its iOS code only as a Swift package, so the iOS build must use Swift Package Manager. Flutter 3.44 and later turn it on by default. If you turned it off, turn it on again:How
permission_handlerturns on the location, motion and notification permissions depends on how it is built:Swift Package Manager CocoaPods permission_handlerreads the usage descriptions inInfo.plistand turns on each matching permission, so the keys above are all it needs. When you build from Xcode.app instead offlutter runorflutter build ios, point it at the file and clear the build cache:Older versions of
permission_handlerbuild with CocoaPods. In that case, turn the permissions on with preprocessor macros in thepost_installblock ofios/Podfile:ios/Podfile Register the sampling package
Register the package in
main(), before you configure theSmartPhoneClientManager:Call
CarpMobileSensing.ensureInitialized()beforeregister(): registering a sampling package before CAMS is initialized throws a null check error.Registering
ContextSamplingPackagemakes the six measure types and the three services known to CAMS. CAMS can then deploy protocols that use them and read them from JSON. It also registers the sub-packages for the location, weather and air quality measures, so do not register those yourself.
Troubleshooting
Set minSdk to 26 or later in android/app/build.gradle.kts. The activity_recognition_flutter plugin requires API level 26.
Turn Swift Package Manager on and build again:
The activity_recognition_flutter plugin has no CocoaPods support, so the iOS build needs Swift Package Manager.
Add NSMotionUsageDescription to ios/Runner/Info.plist, as the CAMS setup in Installation describes. iOS terminates an app that uses motion data without this key.
Build with flutter run, or set PERMISSION_HANDLER_INFO_PLIST as in the Configure iOS step. When you build from Xcode.app, permission_handler cannot find Info.plist. It then compiles out every permission that needs an Info.plist key and reports each one as denied.
Add the INTERNET permission to android/app/src/main/AndroidManifest.xml. Flutter declares it only in the debug and profile manifests, so debug builds work without it.
Next step
Quickstart
Build an app that collects activity, location and mobility features.