Skip to content

Configure Apps

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_apps_package/apps.dart';

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

SamplingPackageRegistry().register(AppsSamplingPackage());

Collection of APPS and APP_USAGE measures can be added to a study protocol like this.

// Define which devices are used for data collection
// In this case, its only this smartphone
Smartphone phone = Smartphone();
protocol.addPrimaryDevice(phone);
// Add an background task that collects the list of installed apps
// and a log of app usage activity
protocol.addTaskControl(
ImmediateTrigger(),
BackgroundTask(measures: [
Measure(type: AppsSamplingPackage.APPS),
Measure(type: AppsSamplingPackage.APP_USAGE),
]),
phone);

Note that both the APPS and the APP_USAGE are one-time measures, and hence only collect a measurement once. If you want to collect app usage e.g., based on app lifecycle events, you could add this to the protocol:

// Add an background task that collects app usage activity when this app
// changes state to foreground.
protocol.addTaskControl(
AppLifecycleTrigger({AppLifecycleState.resumed}),
BackgroundTask(measures: [Measure(type: AppsSamplingPackage.APP_USAGE)]),
phone,
);