public final class HealthDataType
- Object
- HealthDataType
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:
- 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. forId(String)has to be total across framework versions. An app that persisted"vo2Max"and is later restored by an older runtime must getnull, not theIllegalArgumentExceptionthatEnum.valueOfthrows.- 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.
Fields
Methods
public String getId() | The stable, portable identifier for this type. |
public HealthDataKind getKind() | What shape of sample a query for this type returns. |
public HealthUnit getCanonicalUnit() | The unit that samples of this type are normalized to when a query does not request a specific one. |
public HealthAggregationStyle getAggregationStyle() | How this type combines over an aggregation bucket. |
public boolean isIntervalOnly() | true when a sample of this type must span a time range rather than mark an instant. |
public static HealthDataType forId(String id) | Looks a type up by getId(), or null when this version of the framework does not know it. |
public static List<HealthDataType> values() | Every type known to this version of the framework. |
public String toString() | Returns a string representation of the object. |
Inherited methods
Field details
STEPS
public static final HealthDataType STEPSDISTANCE_WALKING_RUNNING
public static final HealthDataType DISTANCE_WALKING_RUNNINGDISTANCE_CYCLING
public static final HealthDataType DISTANCE_CYCLINGDISTANCE_SWIMMING
public static final HealthDataType DISTANCE_SWIMMINGFLIGHTS_CLIMBED
public static final HealthDataType FLIGHTS_CLIMBEDELEVATION_GAINED
public static final HealthDataType ELEVATION_GAINEDACTIVE_ENERGY
public static final HealthDataType ACTIVE_ENERGYBASAL_ENERGY
public static final HealthDataType BASAL_ENERGYEXERCISE_TIME
public static final HealthDataType EXERCISE_TIMEWHEELCHAIR_PUSHES
public static final HealthDataType WHEELCHAIR_PUSHESHEART_RATE
public static final HealthDataType HEART_RATERESTING_HEART_RATE
public static final HealthDataType RESTING_HEART_RATEWALKING_HEART_RATE_AVERAGE
public static final HealthDataType WALKING_HEART_RATE_AVERAGEHEART_RATE_VARIABILITY_SDNN
public static final HealthDataType HEART_RATE_VARIABILITY_SDNNHKQuantityTypeIdentifier ... 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_SATURATIONRESPIRATORY_RATE
public static final HealthDataType RESPIRATORY_RATEBODY_TEMPERATURE
public static final HealthDataType BODY_TEMPERATUREBASAL_BODY_TEMPERATURE
public static final HealthDataType BASAL_BODY_TEMPERATUREVO2_MAX
public static final HealthDataType VO2_MAXBLOOD_PRESSURE
public static final HealthDataType BLOOD_PRESSUREBlood 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_GLUCOSEBODY_MASS
public static final HealthDataType BODY_MASSLEAN_BODY_MASS
public static final HealthDataType LEAN_BODY_MASSBONE_MASS
public static final HealthDataType BONE_MASSBODY_FAT_PERCENTAGE
public static final HealthDataType BODY_FAT_PERCENTAGEBODY_MASS_INDEX
public static final HealthDataType BODY_MASS_INDEXHEIGHT
public static final HealthDataType HEIGHTWAIST_CIRCUMFERENCE
public static final HealthDataType WAIST_CIRCUMFERENCEPOWER
public static final HealthDataType POWERSPEED
public static final HealthDataType SPEEDCYCLING_CADENCE
public static final HealthDataType CYCLING_CADENCERUNNING_CADENCE
public static final HealthDataType RUNNING_CADENCEHYDRATION
public static final HealthDataType HYDRATIONDIETARY_ENERGY
public static final HealthDataType DIETARY_ENERGYNUTRITION
public static final HealthDataType NUTRITIONcom.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 SLEEPSleepSample.WORKOUT
public static final HealthDataType WORKOUTWorkoutSample.MINDFUL_SESSION
public static final HealthDataType MINDFUL_SESSIONMENSTRUATION_FLOW
public static final HealthDataType MENSTRUATION_FLOWINTERMENSTRUAL_BLEEDING
public static final HealthDataType INTERMENSTRUAL_BLEEDINGMethod details
getId
public String getId()android.health.read and android.health.write build hints.getKind
public HealthDataKind getKind()getCanonicalUnit
public HealthUnit getCanonicalUnit()getAggregationStyle
public HealthAggregationStyle getAggregationStyle()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)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()HealthStore.isTypeSupported(HealthDataType).toString
public String toString()