Installation
Add carp_mobile_sensing to a Flutter app and configure Android and iOS.
Install carp_mobile_sensing, configure the Android and iOS host projects, and verify the setup on a physical device.
Use the example app as a baseline
Use these files of the example app as a baseline:
/android/app/src/main/AndroidManifest.xml/android/app/build.gradle.kts/ios/Runner/Info.plist/ios/Runner/AppDelegate.swift
Install the package
Add the dependencies to pubspec.yaml:
Then fetch the packages:
Configure Android
Configure permissions, the services and receivers of the flutter_background and flutter_local_notifications plugins, and the Gradle settings.
Add the required permissions
Add permissions for:
- activity recognition
- notifications, including scheduled notifications
- foreground and background execution
- battery behavior
- the foreground service types used by
flutter_background
android/app/src/main/AndroidManifest.xml Note
FOREGROUND_SERVICE_SPECIAL_USEmust be aligned with the service subtype description shown to users.Declare the plugin services and receivers
Inside
<application>, declare the service forflutter_background:android/app/src/main/AndroidManifest.xml Then declare the service and receivers for
flutter_local_notifications:android/app/src/main/AndroidManifest.xml Enable core library desugaring
flutter_local_notificationsrequires core library desugaring. Enable it and add the desugaring dependency:android/app/build.gradle.kts Add the notification icon
Both
flutter_local_notificationsandflutter_backgrounduseic_launcher.pngas the notification icon. Add it as a drawable resource inandroid/app/src/main/res/drawable/. Typically, you copy/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png.
Configure iOS
Warning
CAMS requires iOS 15.0 or newer. Set the minimum deployment target to 15.0 in Xcode (Runner → General → Minimum Deployments), otherwise the iOS build fails.
Add the Info.plist keys
Add the motion permission used for step tracking:
ios/Runner/Info.plist Optionally, expose the app's files in Finder, as the example app does:
ios/Runner/Info.plist You need
UIFileSharingEnabledto access stored data files through Finder (see Data managers).Configure notifications in AppDelegate
For
flutter_local_notifications, register the plugin registrant callback:ios/Runner/AppDelegate.swift Keep the existing plugin registration:
ios/Runner/AppDelegate.swift
Verify the setup
Refresh and resolve dependencies
Build on each platform
Build on physical devices:
Verify runtime permissions
Grant the notification and motion/activity permissions on the device and confirm the background behavior.
Troubleshooting
Plugin registration errors
As discussed in issue #530, some projects may need to explicitly add plugin dependencies that CAMS uses transitively.
If you see build or runtime plugin registration issues, add the required plugins, for example flutter_local_notifications and flutter_background, directly to your app's pubspec.yaml and run:
For more platform setup and build issues, see Best practices.
Next steps
Using CAMS
Define a study protocol, deploy it and start sampling.
Quickstart
Build a Flutter app that collects step, battery and app lifecycle data.