Considerations and Limitations

Keep these guidelines and limitations in mind when developing features that use the HealthService API.

Supported Data

In this release, HealthService supports reading and writing body-weight records only. Each weight value is expressed in kilograms (kg) or pounds (lbs).

The device’s health platform stores body mass without a unit. When you read records with getWeight(), HealthService converts the values to the unit that you specify in the preferredUnit option. If you don’t specify a unit, HealthService returns values in kilograms.

Device Limitations

HealthService doesn’t manage health data itself. Instead, it reads and writes data in the underlying platform’s health store, Apple HealthKit on iOS or Android Health Connect on Android. While the features provided by HealthService are the same across both platforms, they’re subject to some platform-specific quirks and minor differences.

  • HealthService requires the user to grant your app access to their health data. The exact user experience is governed by the platform. The request happens automatically the first time your component reads or writes data, and is managed by the device itself, but plan for it when you design the user experience of your app.
  • If the user denies permission, the promise is rejected with a HealthServiceFailure.code value of USER_DENIED_PERMISSION. If the user has denied permission and needs to change it to allow access, they can do so in their device’s settings.
  • On Android, the user must have the Health Connect provider installed. If it isn’t installed or needs an update, HealthService prompts the user to install or update it through the Google Play Store, and then the promise is rejected with a PROVIDER_NOT_INSTALLED or PROVIDER_UPDATE_REQUIRED code so that your component can display a message.
  • Read and write access are granted independently. Granting permission to read weight data doesn’t grant permission to write it, and the reverse is also true.

If you’re having trouble getting HealthService to access health data, try these steps.

  1. First, verify that you’ve granted health data permission to the mobile app where your component is running. You can check this in your device’s settings.
  2. Next, on Android, verify that the Health Connect provider is installed and up to date.
  3. Finally, double-check the configuration of the options that you pass to getWeight() and the structure of the record that you pass to writeWeight().

Development Considerations

Virtual devices don’t always have health data when they’re created. To test reading weight history on a virtual device, first write some weight records with writeWeight(), or add records in the device’s native health app.

You can certainly develop the user experience for your component on a desktop or laptop development system. But be sure to test health data functionality on the physical devices on which you plan to deploy your Lightning app.

Apple and Google provide their own guidance for working with health data.

HealthService Considerations

Be aware of these considerations when using HealthService in your Lightning app.

  • HealthService is built on top of mobile operating system and device features. HealthService’s capabilities therefore depend on Android or iOS features, which are subject to change beyond our control. When mobile operating system features change, the behavior of HealthService can change without notice.
  • A Lightning component that uses HealthService can have a custom user interface in the component itself. However, the permission dialog presented by the device can’t be customized.
  • Health data is sensitive. When you read health data from the device, handle it responsibly and in accordance with your company’s privacy policies and applicable regulations.
  • When writing a weight record, it’s the developer’s responsibility to construct the WeightRecord object correctly. Provide a value greater than 0 and a valid unit.
  • If an operation fails, check the error code returned by the promise rejection. A SERVICE_NOT_ENABLED code indicates that the capability is turned off for the app, while permission-related error codes indicate that the user has denied access.