enableBackgroundDelivery method

Future<bool> enableBackgroundDelivery({
  1. List<StatisticsType>? statisticTypes,
  2. List<MetricType>? metricTypes,
  3. List<ActivityConfig>? activityConfigs,
  4. List<SleepConfig>? sleepConfigs,
  5. bool? includeEnhancedPermissions,
})

Enable background checks for new data from Health Connect / HealthKit / Samsung Health Data. Which providers will be used depends on the ones that are enabled.

This call will reset all previous background delivery settings, so it should contain all the data you need to be updated in the background.

App will not be notified about new data directly, instead your backend will receive a webhook. It is your responsibility to inform app if needed (for example with push notification).

Availability

  • iOS: available on iOS 15+
  • Android: can be checked by calling the appropriate Health Connect feature availability method

statisticTypes - Array of statistic types for which background delivery should be enabled. Optional. Defaults to an empty list.

metricTypes - Array of metric types for which background delivery should be enabled. Optional. Defaults to an empty list.

activityConfigs - Array of activity configuration objects for background delivery. Optional. Defaults to an empty list.

sleepConfigs - Array of sleep configuration objects for background delivery. Optional. Defaults to an empty list.

Implementation

Future<bool> enableBackgroundDelivery({
  List<StatisticsType>? statisticTypes,
  List<MetricType>? metricTypes,
  List<ActivityConfig>? activityConfigs,
  List<SleepConfig>? sleepConfigs,
  bool? includeEnhancedPermissions,
}) async {
  final result = await NativeSDKBridgeV3.enableBackgroundDelivery(
    connectionId: connectionId,
    forStatistics: statisticTypes?.map((e) => e.toJson()).toList(),
    forMetrics: metricTypes?.map((e) => e.toJson()).toList(),
    forActivityConfigs: activityConfigs?.map((e) => jsonEncode(e.toJson())).toList(),
    forSleepConfigs: sleepConfigs?.map((e) => jsonEncode(e.toJson())).toList(),
  );

  ExceptionHandler.checkException(result);

  return true;
}