CARP Context Sampling Package

pub package

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

  • dk.cachet.carp.location
  • dk.cachet.carp.geolocation
  • dk.cachet.carp.activity
  • dk.cachet.carp.geofence
  • dk.cachet.carp.air_quality
  • dk.cachet.carp.mobility

See the wiki for further documentation, particularly on available measure types and sampling schemas.

See the CARP Mobile Sensing App for an example of how to build a mobile sensing app in Flutter.

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_context_package: ^latest

Android Integration

Add the following to your app's manifest.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.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <!-- The following permissions are used in the Context Package -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <!-- For Android 9 (API 28 and earlier), use: -->
    <uses-permission android:name="" />
    <!-- for Android 10 (API 29 and later), use: -->
    <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />


NOTE: For Android 10 (API 29 and later) use the following permission:

<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />

See Privacy changes in Android 10.

NOTE: Version 0.5.0 is migrated to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library. See Flutter AndroidX compatibility

iOS Integration

Add the following permissions in the Info.plist file located in ios/Runner (use your own text for explanation in the <string> tags):

<string>Uses the location API to record location.</string>
<string>Uses the location API to record location.</string>
<string>Uses the location API to record location.</string>
<string>Detects activity.</string>

In app settings enable Background Modes and check Location Updates.

iOS Setup

Using it

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

import 'package:carp_mobile_sensing/carp_mobile_sensing.dart';
import 'package:carp_context_package/context.dart';

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


The WeatherMeasure and the AirQualityMeasure require API key from the Open Weather API and Air Quality Open Data Platform, respectively. Please make sure to obtain such API keys for your app and use these in specifying your measures, like this:

  // Add an automatic task that collects weather and air_quality every 30 miutes.
  // Not that API keys for the weather and air_quality measure must be specified.
        period: Duration(minutes: 30),
        duration: Duration(seconds: 10),
            type: ContextSamplingPackage.WEATHER,
            name: 'Weather',
                "Collects local weather from the WeatherAPI web service",
            apiKey: 'Open_Weather_API_key_goes_here'))
            type: ContextSamplingPackage.AIR_QUALITY,
            name: 'Air Quality',
                "Collects local air quality from the Air Quality Index (AQI) web service",
            apiKey: 'AQI_API_key_goes_here')),


A library for collecting context information on: