Skip to content

HealthProbe

Collects health data from Apple Health or Google Health Connect.

Created by the HealthSamplingPackage for the HealthSamplingPackage.HEALTH measure and configured by a HealthSamplingConfiguration. Each time it is resumed, it fetches the configured health data types back to the last time data was collected and emits one HealthData measurement per data point. Use it with a trigger that runs regularly, such as a PeriodicTrigger, or from a HealthAppTask that the user starts.

Key points:

  • On initialize, it removes types not supported on this platform and adds the rest to the HealthServiceManager.
  • It collects nothing if permissions are missing, the type list is empty, or the start time is after the end time.
  • It pauses itself 20 seconds after a collection.
  • Errors from the health plugin are logged and the resume fails.
Inheritance

Constructors

HealthProbe

HealthProbe()

Properties

deviceManager

HealthServiceManager get deviceManager
override
set deviceManager (DeviceManager<DeviceConfiguration<DeviceRegistration>, DeviceRegistration> value)
inherited

The device that this probes uses to collect data.

samplingConfiguration

HealthSamplingConfiguration get samplingConfiguration
override

The sampling configuration for this probe.

Configuration is obtained in the following order:

Returns null in case no configuration is found.

See also the section on Sampling schemes and configurations in the CARP Core Framework. In addition to CARP Core, CARP Mobile Sensing also supports sampling schemes in the sampling packages, which are used as the 4th possible configuration in the list above.

stream

Stream<Measurement> get stream

A stream that only carries collection errors.

Measurements are emitted on measurements, not on this stream.

Methods

hasPermissions

Future<bool> hasPermissions()

Whether permission is granted to read the health data types in the samplingConfiguration.

See HealthServiceManager.hasHealthPermissions for the iOS caveat.

onInitialize

bool onInitialize()
override

Callback when this executor is initialized. Returns true if successfully initialized, false otherwise.

Note that this is a non-async method and should hence be 'light-weight' and not block execution for a long duration.

onResume

Future<bool> onResume()
override

Callback when this executor is resumed. Returns true if successfully resumed, false otherwise.

requestPermissions

Future<bool> requestPermissions()
override

Requests permission to read the health data types in the samplingConfiguration, if not already granted.

Note that this shows the permission dialog to the user, asking for access to the health data. If the user denies access, this method returns false.

Note that on Android, if the user denies access to the health data types TWICE, then the permissions are permanently denied and the app cannot ask anymore. In this case, this method cannot be used to request permissions. Instead, the user must manually go to the settings of the phone and enable the permissions.

validateHealthDataTypes

void validateHealthDataTypes()

Removes the health data types in samplingConfiguration that are not supported on the current platform (iOS or Android).

Logs a warning for each removed type. Called when the probe is initialized.