CARP Communication Sampling Package

pub package pub points github stars MIT License arXiv

This library contains a sampling package for communication sampling to work with the carp_mobile_sensing package. This packages supports sampling of the following Measure types:

  • dk.cachet.carp.phone_log - the phone log.
  • dk.cachet.carp.text_message_log - the text (sms) message log.
  • dk.cachet.carp.text_message - incoming text (sms) messages.
  • dk.cachet.carp.calendar - all calendar entries.

Note that collection of phone and text message data is only supported on Android.

See the wiki for further documentation, particularly on available measure types. See the CARP Mobile Sensing App for an example of how to build a mobile sensing app in Flutter.

This package have implemented default privacy protection of text messages, phone numbers, and calendar entries as part of the default Privacy Schema. These functions are implemented in the communication_privacy.dart file and use standard SHA1 hashing.

For Flutter plugins for other CARP products, see CARP Mobile Sensing in Flutter.

If you're interested in writing you own sampling packages for CARP, see the description on how to extend CARP on the wiki.


To use this package, add the following to you pubspc.yaml file. Note that this package only works together with carp_mobile_sensing.

    sdk: flutter
  carp_mobile_sensing: ^latest
  carp_communication_package: ^latest

Android Integration

Add the following to your app's AndroidManifest.xml file located in android/app/src/main:

<manifest xmlns:android=""

  <!-- The following permissions are used for CARP Mobile Sensing -->
  <uses-permission android:name="android.permission.CALL_PHONE"/>
  <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
  <uses-permission android:name="android.permission.READ_PHONE_NUMBERS"/>
  <uses-permission android:name="android.permission.READ_SMS"/>
  <uses-permission android:name="android.permission.RECEIVE_SMS"/>
  <uses-permission android:name="android.permission.READ_CALENDAR"/>
  <!-- Even though we only want to READ the calendar, for some unknown 
       reason we also need to add the WRITE permission. -->
  <uses-permission android:name="android.permission.WRITE_CALENDAR"/>

    <!-- Registration of broadcast receiver to listen to SMS messages 
         when the app is in the background -->
   <receiver android:name="com.shounakmulay.telephony.sms.IncomingSmsReceiver"
     android:permission="android.permission.BROADCAST_SMS" android:exported="true">
        <action android:name="android.provider.Telephony.SMS_RECEIVED"/>


iOS Integration

Add this permission in the Info.plist file located in ios/Runner:


Using it

To use this package, import it into your app together with the carp_mobile_sensing package:

import 'package:carp_core/carp_core.dart';
import 'package:carp_mobile_sensing/carp_mobile_sensing.dart';
import 'package:carp_communication_package/communication.dart';

Before creating a study and running it, register this package in the SamplingPackageRegistry.


Collection of communication measures can be added to a study protocol like this.

// Create a study protocol
StudyProtocol protocol = StudyProtocol(
  ownerId: '',
  name: 'Communication Sensing Example',

// Define which devices are used for data collection
// In this case, its only this smartphone
Smartphone phone = Smartphone();

// Add an automatic task that collects SMS messages in/out
        measures: [Measure(type: CommunicationSamplingPackage.TEXT_MESSAGE)]),

// Add an automatic task that every 3 hour collects the logs for:
//  * in/out SMS
//  * in/out phone calls
//  * calendar entries
    PeriodicTrigger(period: const Duration(hours: 3)),
    BackgroundTask(measures: [
      Measure(type: CommunicationSamplingPackage.PHONE_LOG),
      Measure(type: CommunicationSamplingPackage.TEXT_MESSAGE_LOG),
      Measure(type: CommunicationSamplingPackage.CALENDAR),


A library for collecting communication data, from