# Class HealthDataType

java.lang.Object
com.codename1.health.HealthDataType

public final class HealthDataType extends Object

A kind of health data -- steps, heart rate, sleep, body mass. Instances are interned constants, so `==` is a valid identity test.

##### Why this is not an enum

Three reasons, in order of how much trouble each would cause:

1. Each constant carries a `HealthUnit`, and a Java enum constructor that references another class's statics is an initialization-order hazard -- the unit would be null for whichever class loaded first.
2. `forId(String)` has to be total across framework versions. An app that persisted `"vo2Max"` and is later restored by an older runtime must get `null`, not the `IllegalArgumentException` that `Enum.valueOf` throws.
3. Ports need to attach platform metadata to types without the core knowing about it.

##### There is no custom type

Deliberately no `HealthDataType.custom(String)`. A custom type would have no canonical unit, no aggregation style and no cross-platform mapping -- an untyped string passthrough that works on exactly one platform, which is the failure mode this API exists to prevent. Adding a type is a change to this class.

##### Permissions are declared, not inferred

The build server cannot see which of these constants an app touches: constant references compile to field reads, and the class scanner only records type and method references. Android's per-type `android.permission.health.*` set therefore comes from the `android.health.read` and `android.health.write` build hints, which use the `getId()` values below as tokens. This also matches Google Play policy, which requires declaring exactly the data types you use.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final HealthDataType`
  `ACTIVE_ENERGY`
  `static final HealthDataType`
  `BASAL_BODY_TEMPERATURE`
  `static final HealthDataType`
  `BASAL_ENERGY`
  `static final HealthDataType`
  `BLOOD_GLUCOSE`
  `static final HealthDataType`
  `BLOOD_PRESSURE`
  Blood pressure, as a single sample carrying both systolic and diastolic values -- see `BloodPressureSample`.
  `static final HealthDataType`
  `BODY_FAT_PERCENTAGE`
  `static final HealthDataType`
  `BODY_MASS`
  `static final HealthDataType`
  `BODY_MASS_INDEX`
  `static final HealthDataType`
  `BODY_TEMPERATURE`
  `static final HealthDataType`
  `BONE_MASS`
  `static final HealthDataType`
  `CYCLING_CADENCE`
  `static final HealthDataType`
  `DIETARY_ENERGY`
  `static final HealthDataType`
  `DISTANCE_CYCLING`
  `static final HealthDataType`
  `DISTANCE_SWIMMING`
  `static final HealthDataType`
  `DISTANCE_WALKING_RUNNING`
  `static final HealthDataType`
  `ELEVATION_GAINED`
  `static final HealthDataType`
  `EXERCISE_TIME`
  `static final HealthDataType`
  `FLIGHTS_CLIMBED`
  `static final HealthDataType`
  `HEART_RATE`
  `static final HealthDataType`
  `HEART_RATE_VARIABILITY_SDNN`
  Heart-rate variability as the standard deviation of NN intervals, the metric both platforms expose (`HKQuantityTypeIdentifier` `... HeartRateVariabilitySDNN`).
  `static final HealthDataType`
  `HEIGHT`
  `static final HealthDataType`
  `HYDRATION`
  `static final HealthDataType`
  `INTERMENSTRUAL_BLEEDING`
  `static final HealthDataType`
  `LEAN_BODY_MASS`
  `static final HealthDataType`
  `MENSTRUATION_FLOW`
  `static final HealthDataType`
  `MINDFUL_SESSION`
  A mindfulness or meditation session.
  `static final HealthDataType`
  `NUTRITION`
  A logged food or meal carrying an arbitrary set of nutrients -- see `com.codename1.health.nutrition`.
  `static final HealthDataType`
  `OXYGEN_SATURATION`
  `static final HealthDataType`
  `POWER`
  `static final HealthDataType`
  `RESPIRATORY_RATE`
  `static final HealthDataType`
  `RESTING_HEART_RATE`
  `static final HealthDataType`
  `RUNNING_CADENCE`
  `static final HealthDataType`
  `SLEEP`
  A sleep session with optional stage detail -- see `SleepSample`.
  `static final HealthDataType`
  `SPEED`
  `static final HealthDataType`
  `STEPS`
  `static final HealthDataType`
  `VO2_MAX`
  `static final HealthDataType`
  `WAIST_CIRCUMFERENCE`
  `static final HealthDataType`
  `WALKING_HEART_RATE_AVERAGE`
  `static final HealthDataType`
  `WHEELCHAIR_PUSHES`
  `static final HealthDataType`
  `WORKOUT`
  A workout or exercise session -- see `WorkoutSample`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static HealthDataType`
  `forId(String id)`
  Looks a type up by `getId()`, or `null` when this version of the framework does not know it.
  `HealthAggregationStyle`
  `getAggregationStyle()`
  How this type combines over an aggregation bucket.
  `HealthUnit`
  `getCanonicalUnit()`
  The unit that samples of this type are normalized to when a query does not request a specific one.
  `String`
  `getId()`
  The stable, portable identifier for this type.
  `HealthDataKind`
  `getKind()`
  What shape of sample a query for this type returns.
  `boolean`
  `isIntervalOnly()`
  `true` when a sample of this type must span a time range rather than mark an instant.
  `String`
  `toString()`
  Returns a string representation of the object.
  `static List<HealthDataType>`
  `values()`
  Every type known to this version of the framework.

  ### Methods inherited from class Object

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

- ## Field Details

  - ### STEPS

    public static final HealthDataType STEPS

  - ### DISTANCE_WALKING_RUNNING

    public static final HealthDataType DISTANCE_WALKING_RUNNING

  - ### DISTANCE_CYCLING

    public static final HealthDataType DISTANCE_CYCLING

  - ### DISTANCE_SWIMMING

    public static final HealthDataType DISTANCE_SWIMMING

  - ### FLIGHTS_CLIMBED

    public static final HealthDataType FLIGHTS_CLIMBED

  - ### ELEVATION_GAINED

    public static final HealthDataType ELEVATION_GAINED

  - ### ACTIVE_ENERGY

    public static final HealthDataType ACTIVE_ENERGY

  - ### BASAL_ENERGY

    public static final HealthDataType BASAL_ENERGY

  - ### EXERCISE_TIME

    public static final HealthDataType EXERCISE_TIME

  - ### WHEELCHAIR_PUSHES

    public static final HealthDataType WHEELCHAIR_PUSHES

  - ### HEART_RATE

    public static final HealthDataType HEART_RATE

  - ### RESTING_HEART_RATE

    public static final HealthDataType RESTING_HEART_RATE

  - ### WALKING_HEART_RATE_AVERAGE

    public static final HealthDataType WALKING_HEART_RATE_AVERAGE

  - ### HEART_RATE_VARIABILITY_SDNN

    public static final HealthDataType HEART_RATE_VARIABILITY_SDNN
    Heart-rate variability as the standard deviation of NN intervals, the metric both platforms expose (`HKQuantityTypeIdentifier` `... HeartRateVariabilitySDNN`). Other HRV metrics -- RMSSD, frequency domain -- are not stored by either platform; derive them yourself from the RR intervals a chest strap reports through `com.codename1.health.sensors`.

  - ### OXYGEN_SATURATION

    public static final HealthDataType OXYGEN_SATURATION

  - ### RESPIRATORY_RATE

    public static final HealthDataType RESPIRATORY_RATE

  - ### BODY_TEMPERATURE

    public static final HealthDataType BODY_TEMPERATURE

  - ### BASAL_BODY_TEMPERATURE

    public static final HealthDataType BASAL_BODY_TEMPERATURE

  - ### VO2_MAX

    public static final HealthDataType VO2_MAX

  - ### BLOOD_PRESSURE

    public static final HealthDataType BLOOD_PRESSURE

    Blood pressure, as a single sample carrying both systolic and diastolic values -- see `BloodPressureSample`.

    HealthKit models this as an `HKCorrelation` of two separate quantity samples; Health Connect has a single `BloodPressureRecord` and no correlation concept at all. This API follows Health Connect. There is deliberately no portable `Correlation` type, because it would be a fiction maintained in one port only.

    Local and simulator only in this release. Neither phone carries this type: the iOS map has no `blood_pressure` entry, so the correlation assembly the port will need is not written yet, and Health Connect's record is not mapped either. A read or write of it on a device is refused with `HealthError.TYPE_NOT_SUPPORTED` rather than dropped silently. Take the reading off the sensor session and keep it yourself until then -- see `BloodPressureSample`.

  - ### BLOOD_GLUCOSE

    public static final HealthDataType BLOOD_GLUCOSE

  - ### BODY_MASS

    public static final HealthDataType BODY_MASS

  - ### LEAN_BODY_MASS

    public static final HealthDataType LEAN_BODY_MASS

  - ### BONE_MASS

    public static final HealthDataType BONE_MASS

  - ### BODY_FAT_PERCENTAGE

    public static final HealthDataType BODY_FAT_PERCENTAGE

  - ### BODY_MASS_INDEX

    public static final HealthDataType BODY_MASS_INDEX

  - ### HEIGHT

    public static final HealthDataType HEIGHT

  - ### WAIST_CIRCUMFERENCE

    public static final HealthDataType WAIST_CIRCUMFERENCE

  - ### POWER

    public static final HealthDataType POWER

  - ### SPEED

    public static final HealthDataType SPEED

  - ### CYCLING_CADENCE

    public static final HealthDataType CYCLING_CADENCE

  - ### RUNNING_CADENCE

    public static final HealthDataType RUNNING_CADENCE

  - ### HYDRATION

    public static final HealthDataType HYDRATION

  - ### DIETARY_ENERGY

    public static final HealthDataType DIETARY_ENERGY

  - ### NUTRITION

    public static final HealthDataType NUTRITION
    A logged food or meal carrying an arbitrary set of nutrients -- see `com.codename1.health.nutrition`. Produces a `NutritionSample` rather than a plain quantity, because a single entry sets many nutrient fields at once.

  - ### SLEEP

    public static final HealthDataType SLEEP
    A sleep session with optional stage detail -- see `SleepSample`.

  - ### WORKOUT

    public static final HealthDataType WORKOUT
    A workout or exercise session -- see `WorkoutSample`.

  - ### MINDFUL_SESSION

    public static final HealthDataType MINDFUL_SESSION
    A mindfulness or meditation session.

  - ### MENSTRUATION_FLOW

    public static final HealthDataType MENSTRUATION_FLOW

  - ### INTERMENSTRUAL_BLEEDING

    public static final HealthDataType INTERMENSTRUAL_BLEEDING

- ## Method Details

  - ### getId

    public String getId()
    The stable, portable identifier for this type. Safe to persist and to send to a server; also the token used by the `android.health.read` and `android.health.write` build hints.

  - ### getKind

    public HealthDataKind getKind()
    What shape of sample a query for this type returns.

  - ### getCanonicalUnit

    public HealthUnit getCanonicalUnit()
    The unit that samples of this type are normalized to when a query does not request a specific one. Null for types with no natural unit -- sessions and categories.

  - ### getAggregationStyle

    public HealthAggregationStyle getAggregationStyle()
    How this type combines over an aggregation bucket.

  - ### isIntervalOnly

    public boolean isIntervalOnly()

    `true` when a sample of this type must span a time range rather than mark an instant. A step count belongs to an interval; a body mass reading belongs to a moment.

    `HealthStore` rejects an instantaneous write of an interval-only type with `HealthError.INVALID_ARGUMENT`, rather than letting the platform throw something opaque later.

  - ### forId

    public static HealthDataType forId(String id)
    Looks a type up by `getId()`, or `null` when this version of the framework does not know it. Total by design -- see the class documentation.

  - ### values

    public static List<HealthDataType> values()
    Every type known to this version of the framework. Note that a given platform supports a subset -- check `HealthStore.isTypeSupported(HealthDataType)`.

  - ### toString

    public String toString()
    Description copied from class: `Object`
    Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
    Overrides:
      `toString` in class `Object`