Skip to content
CARP Docs
Ask AISystemLightDark
On this page

Apps Sampling Package

Collect the installed apps and per-app usage time from Android phones in a CARP Mobile Sensing study.

Copy MarkdownOpen inOpen in GitHubView as MarkdownOpen in Scira AIOpen in ChatGPTOpen in ClaudeOpen in Cursor

carp_apps_package adds two measures to a CARP Mobile Sensing (CAMS) study: the installed apps and how long each app was in the foreground. Use them when a study looks at how participants use their phone.

The package reads the app list with the installed_apps plugin and the usage times from Android's usage statistics with the app_usage plugin.

pub.devAPI referenceGitHub

Android only

Both measures work on Android only. On iOS, CAMS skips them and logs a warning, so a protocol that contains them still runs on iOS, without app data.

Features

Installed apps

Lists the non-system apps that the participant can open from the launcher, with package name, version and last update time.

App usage

Records how long each app was in the foreground over a time window, from Android's usage statistics.

Measure types

The package has two one-time measure types, which collect once each time their trigger fires:

Measure typeDataAndroidiOS
dk.cachet.carp.appsInstalled apps that have a launcher entry, without system appsYesNo
dk.cachet.carp.appusageForeground time per app over a time windowYesNo

For the measure types of the other sampling packages, see Measure types.

Requirements

ComponentRequirement
Dart SDK3.10 or later, the CAMS minimum
Flutter3.38.1 or later, the CAMS minimum
carp_mobile_sensing2.2.0 or later
AndroidAPI level 24 (Android 7.0) or later, the CAMS minimum
iOSNot supported

How it works

Adding the package to a study takes three steps:

  1. Register the package

    Registering an AppsSamplingPackage in the SamplingPackageRegistry makes the two measure types and their data classes known to CAMS.

  2. Add the measures with a repeating trigger

    One-time measures collect only when their trigger fires, so use a trigger that repeats, such as a PeriodicTrigger. App usage also needs its own HistoricSamplingConfiguration, so that each collection continues where the previous one ended, also after an app restart.

  3. Deploy and grant usage access

    After you deploy the protocol, CAMS collects both measures each time the trigger fires. For app usage, the participant must also turn on Usage access for the app in Android settings. The app_usage plugin opens that screen when access is missing.

This example registers the package and collects both measures once a day:

import 'package:carp_core/carp_core.dart' hide Smartphone;
import 'package:carp_mobile_sensing/carp_mobile_sensing.dart';
import 'package:carp_apps_package/apps.dart';

void main() {
  CarpMobileSensing.ensureInitialized();
  SamplingPackageRegistry().register(AppsSamplingPackage());

  final phone = Smartphone();
  final protocol = SmartphoneStudyProtocol(
    ownerId: 'owner@example.com',
    name: 'Daily app use',
    dataEndPoint: SQLiteDataEndPoint(),
  )..addPrimaryDevice(phone);

  // One-time measures collect when the trigger fires: here once a day
  protocol.addTaskControl(
    PeriodicTrigger(period: const Duration(days: 1)),
    BackgroundTask(
      measures: [
        Measure(type: AppsSamplingPackage.APPS),
        Measure(
          type: AppsSamplingPackage.APP_USAGE,
          samplingConfiguration: HistoricSamplingConfiguration( 
            past: const Duration(days: 1),
          ),
        ),
      ],
    ),
    phone,
  );

  // ... deploy the protocol and start sampling
}

Next steps

Installation

Add the package and the Android manifest entries.

Quickstart

Build an app that collects both measures and prints them.

Installed apps

The apps installed on an Android phone, with version and update time.

App usage

Foreground time per app over a time window, from Android usage statistics.

Quick links

Page · DocumentationCARP DocumentationPage · DocumentationIntroductionPage · DocumentationQuickstartPage · DocumentationTerminologyPage · DocumentationArchitecture