Skip to content

HealthServiceManager

The DeviceManager for the HealthService.

Owns the Health plugin instance, keeps the set of health data types to access, and checks and requests permissions for them.

Key points:

  • Types come from each HealthProbe (on initialize) and from the default sampling configuration of the HealthService (on configure).
  • Connecting always succeeds once permissions are granted.
  • On iOS, hasPermissions is true as soon as types are registered, because Apple Health does not disclose whether read access is granted.
  • On Android below SDK level 34, it logs a warning that Health Connect must be installed as a separate app.
Inheritance

Constructors

HealthServiceManager

HealthServiceManager([
  1. HealthService? configuration
])

Properties

canConnect

bool get canConnect
override

Determines whether a connection can be made at this point in time to the device.

displayName

String get displayName
override

service

Health? get service

The Health plugin, or null if this manager is not configured yet.

types

List<HealthDataType> get types

The health data types this service accesses.

Methods

addTypes

void addTypes(
  1. List<HealthDataType> types
)

Add a set of health types this service should access.

Types not supported on the current platform are ignored and logged as a warning.

createRegistration

ServiceRegistration createRegistration()
override

Create a device registration which can be used to configure this device for deployment.

This method is used when a device is connected and a registration for this device is needed in the deployment and hence in the deployment service. The registration is typically created from the device information of the real device, e.g., the ID, name, and BLE address of the smartphone or a connected Bluetooth device.

gatherTypesFrom

void gatherTypesFrom(
  1. HealthService? service
)

Adds the health data types from the default sampling configuration of service for the HealthSamplingPackage.HEALTH measure, so that the right permissions can be requested.

Called when this manager is configured.

hasHealthPermissions

Future<bool> hasHealthPermissions(
  1. List<HealthDataType> types
)

Checks if the service has permissions to access the list of health types.

This method is called by the HealthProbe when it needs to access health data and is a more specific method than hasPermissions. Returns true if types is empty, and false if the check fails.

Note that this method always returns false on iOS, as there is no way to know if permissions are granted.

onConfigure

void onConfigure()
override

Callback on configure.

When called, the configuration and the registration is available.

Is to be overridden in sub-classes. Note, however, that it must not be doing a lot of work on startup.

onConnect

Future<DeviceStatus> onConnect()
override

Callback on connect. Returns the DeviceStatus of the device.

Can be overridden for device-specific connection handling.

onDisconnect

Future<bool> onDisconnect()
override

Callback on disconnect.

This method is called after all sampling on this device has been stopped, and the device manager is trying to disconnect from the real device.

Is to be overridden in sub-classes and implement device-specific disconnection.

onHasPermissions

Future<bool> onHasPermissions()
override

Callback on hasPermissions.

Can be overridden in sub-classes for device-specific permission handling.

onRequestPermissions

Future<void> onRequestPermissions()
override

Callback on requestPermissions.

Can be overridden for device-specific permission handling.

requestHealthPermissions

Future<bool> requestHealthPermissions(
  1. List<HealthDataType> types
)

Requests permissions for the list of health types.

This method is called by the HealthProbe when it needs to access health data and is a more specific method than requestPermissions. It shows the OS permission dialog. Returns true if types is empty, and false if the request fails.