Quickstart
Build a Flutter app that collects the call log, text messages and calendar events with hashed identifiers.
The finished app reads calls, text messages and calendar events on a schedule and prints them with phone numbers and texts hashed.
Prerequisites
- The setup in Installation, including the CARP Mobile Sensing (CAMS) setup it builds on.
- A physical phone with some calls, text messages and calendar events. On iOS, only the calendar is collected.
Complete example
Replace the contents of lib/main.dart with:
How it works
| Stage | What it does |
|---|---|
| 1. Register | Makes the four measure types, the JSON types of their data and their privacy transformers known to CAMS. CarpMobileSensing.ensureInitialized() runs first, because registering needs an initialized CAMS. |
| 2. Protocol | privacySchemaName: PrivacySchema.DEFAULT turns on the privacy transformers, which hash phone numbers, contact names, message texts and event titles. Without it, CAMS stores them in clear text. |
| 3. Calls and calendar | PeriodicTrigger fires when sampling starts and then every 3 hours. Each run collects from the end of the previous run, and the first run goes back 1 day. |
| 4. Text messages | The text message log returns every message in the inbox and the sent folder on each run, so a daily trigger keeps the duplicates down. |
| 5. Deploy | CAMS asks for the permissions of all measures and then starts the triggers. The app adds the study only on the first run: on later runs, configure() restores the saved study. |
| 6. Print | client.measurements delivers each measurement after the privacy transformers have run. |
The phone log and the calendar keep their last collection time in memory. After an app restart, their first run goes back 1 day again. To keep the time across restarts, see Calls and text messages.
Run the app
Connect the phone and run:
On Android, CAMS asks for access to phone calls, call logs, the calendar and SMS; on iOS, it asks for calendar access only. Allow them.
The first run starts right away, and the console prints a measurement for each measure that runs on the phone. CAMS also adds a dk.cachet.carp.triggeredtask measurement each time a trigger fires.
A calendar measurement looks like this, with the event titles and descriptions hashed and the JSON formatted for readability:
For the fields of each measure, see Calls and text messages and Calendar.
Troubleshooting
Check that the participant allowed every dialog, and that the permissions are in the merged manifest. An app that removes the restricted permissions for Google Play collects the calendar only. See Installation for the entries each measure needs.
Use an Android phone to collect calls and text messages: iOS gives apps no access to them, so CAMS skips those measures on iOS.
Next steps
Calls and text messages
What the call and message measures collect, and their data.
Calendar
Which events the calendar measure collects, and their fields.
Privacy
Hash phone numbers, message texts and event titles before storage.