# Class Health

java.lang.Object
com.codename1.health.Health

public class Health extends Object

Entry point for the Codename One health API -- reading and writing health data, watching it for changes, recording workouts, and streaming from Bluetooth health sensors.

Obtain the platform implementation via `getInstance()`; the returned object is owned by the active port and is never `null`.

The API is split by role:

- `getStore()` -- the platform health store: samples, aggregates, writes and change subscriptions.
- `getWorkouts()` -- live and recorded workout sessions.
- `getSensors()` -- standard Bluetooth GATT health sensors: heart-rate straps, power meters, scales, blood-pressure cuffs, glucose meters.

##### Quick start

    Health health = Health.getInstance();
    if (health.getAvailability() != HealthAvailability.AVAILABLE) {
        health.openProviderSetup();
        return;
    }
    HealthStore store = health.getStore();
    store.requestAuthorization(HealthAccess.read(HealthDataType.STEPS))
         .onResult((asked, err) -> {
             if (err == null) {
                 readTodaysSteps(store);
             }
         });

##### Two things that will surprise you

You cannot ask whether you may read. HealthKit deliberately refuses to disclose read authorization -- a denied read looks exactly like an empty result. So `requestAuthorization` resolving `true` means the user was asked, not that they agreed, and an empty query result means "denied or no data" with no way to tell which. Never render that to a user as "you denied access"; say "no data available". See `HealthStore.getReadAuthorizationStatus(HealthDataType)`.

Android never wakes your app for new data. Health Connect has no push mechanism, so subscriptions there are drained when your app runs. Check `HealthSubscription.isPushDelivery()` rather than assuming.

##### Threading

Every method may be called from the EDT and returns immediately; every callback is delivered on the EDT. The one qualification is `HealthBackgroundListener`, which may run with no visible UI after the OS relaunched your app in the background.

##### Platform support

- iOS / watchOS -- HealthKit, including background delivery and (on watchOS, and on iOS 26 and later) live workout sessions. Requires the HealthKit entitlement and privacy usage strings; the build fails with an actionable message if they are missing.
- Android -- Health Connect, including exercise sessions. Requires the provider app, a privacy-policy declaration and per-type permissions declared through build hints.
- JavaSE simulator -- a scriptable virtual health store (Simulate -> Health Simulation) with synthetic data, permission scripting and fault injection.
- Desktop and JavaScript -- no platform store exists, so these report `HealthAvailability.LOCAL_ONLY` and keep data locally. The sensor API works fully wherever Bluetooth LE does.
- tvOS and all other ports -- this base class is returned as-is and reports health as unsupported; operations fail fast with `HealthError.NOT_SUPPORTED`.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `Health()`
  Ports construct subclasses.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `HealthAvailability`
  `getAvailability()`
  Whether a health store is usable right now, and if not, why.
  `List<String>`
  `getConfigurationProblems()`
  Build-configuration problems detected at runtime -- a missing `ios.NSHealthShareUsageDescription` build hint, an absent Health Connect privacy-policy declaration.
  `static Health`
  `getInstance()`
  Returns the platform-specific singleton owned by the current port.
  `HealthSensors`
  `getSensors()`
  Bluetooth health sensors.
  `HealthStore`
  `getStore()`
  The platform health store.
  `WorkoutManager`
  `getWorkouts()`
  Workout recording.
  `boolean`
  `isSupported()`
  `true` when this port exposes health data in any form.
  `AsyncResource<Boolean>`
  `openHealthSettings()`
  Opens the operating system screen where the user can change health permissions -- Settings on iOS, the Health Connect permission screen on Android.
  `AsyncResource<Boolean>`
  `openProviderSetup()`
  Sends the user to install or update the Health Connect provider.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Health

    protected Health()
    Ports construct subclasses. Application code obtains the active instance via `getInstance()`.

- ## Method Details

  - ### getInstance

    public static Health getInstance()
    Returns the platform-specific singleton owned by the current port. On ports without health support this returns a base `Health` instance that reports the feature as unsupported, so calling code never needs a `null` check or a platform-specific `if`.

  - ### isSupported

    public boolean isSupported()
    `true` when this port exposes health data in any form. `false` on the fallback base class.

  - ### getAvailability

    public HealthAvailability getAvailability()
    Whether a health store is usable right now, and if not, why. Check this before anything else -- on Android the provider app may be missing or out of date, which the user can fix.

  - ### getStore

    public HealthStore getStore()
    The platform health store. Never null: on ports without one this returns a no-op store whose every operation fails with `HealthError.NOT_SUPPORTED`. Branch on `HealthStore.isSupported()`.

  - ### getWorkouts

    public WorkoutManager getWorkouts()
    Workout recording. Never null.

  - ### getSensors

    public HealthSensors getSensors()
    Bluetooth health sensors. Never null, and -- unlike the other two -- not a no-op on ports without a health store: the sensor layer is built entirely on `com.codename1.bluetooth.le`, so it works anywhere Bluetooth LE does, including the desktop and JavaScript ports.

  - ### openHealthSettings

    public AsyncResource<Boolean> openHealthSettings()

    Opens the operating system screen where the user can change health permissions -- Settings on iOS, the Health Connect permission screen on Android. Resolves `false` where no such screen exists.

    This is the right response to a query that came back empty when you expected data, since on iOS you cannot tell denial from absence.

  - ### openProviderSetup

    public AsyncResource<Boolean> openProviderSetup()
    Sends the user to install or update the Health Connect provider. Meaningful when `getAvailability()` is `HealthAvailability.PROVIDER_NOT_INSTALLED` or `HealthAvailability.PROVIDER_UPDATE_REQUIRED`; resolves `false` elsewhere.

  - ### getConfigurationProblems

    public List<String> getConfigurationProblems()

    Build-configuration problems detected at runtime -- a missing `ios.NSHealthShareUsageDescription` build hint, an absent Health Connect privacy-policy declaration. Empty when the app is configured correctly.

    Operations that need a missing entry throw `HealthConfigurationException` carrying the same text. This method reports the same diagnostics without throwing, so a diagnostics screen or a test can assert on them.