Class 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypeBlood pressure, as a single sample carrying both systolic and diastolic values -- seeBloodPressureSample.static final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypeHeart-rate variability as the standard deviation of NN intervals, the metric both platforms expose (HKQuantityTypeIdentifier... HeartRateVariabilitySDNN).static final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypeA mindfulness or meditation session.static final HealthDataTypeA logged food or meal carrying an arbitrary set of nutrients -- seecom.codename1.health.nutrition.static final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypeA sleep session with optional stage detail -- seeSleepSample.static final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypestatic final HealthDataTypeA workout or exercise session -- seeWorkoutSample. -
Method Summary
Modifier and TypeMethodDescriptionstatic HealthDataTypeLooks a type up bygetId(), ornullwhen this version of the framework does not know it.How this type combines over an aggregation bucket.The unit that samples of this type are normalized to when a query does not request a specific one.getId()The stable, portable identifier for this type.getKind()What shape of sample a query for this type returns.booleantruewhen a sample of this type must span a time range rather than mark an instant.toString()Returns a string representation of the object.static List<HealthDataType> values()Every type known to this version of the framework.
-
Field Details
-
STEPS
-
DISTANCE_WALKING_RUNNING
-
DISTANCE_CYCLING
-
DISTANCE_SWIMMING
-
FLIGHTS_CLIMBED
-
ELEVATION_GAINED
-
ACTIVE_ENERGY
-
BASAL_ENERGY
-
EXERCISE_TIME
-
WHEELCHAIR_PUSHES
-
HEART_RATE
-
RESTING_HEART_RATE
-
WALKING_HEART_RATE_AVERAGE
-
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 throughcom.codename1.health.sensors. -
OXYGEN_SATURATION
-
RESPIRATORY_RATE
-
BODY_TEMPERATURE
-
BASAL_BODY_TEMPERATURE
-
VO2_MAX
-
BLOOD_PRESSURE
Blood pressure, as a single sample carrying both systolic and diastolic values -- see
BloodPressureSample.HealthKit models this as an
HKCorrelationof two separate quantity samples; Health Connect has a singleBloodPressureRecordand no correlation concept at all. This API follows Health Connect, and the iOS port assembles and disassembles the correlation. There is deliberately no portableCorrelationtype, because it would be a fiction maintained in one port only. -
BLOOD_GLUCOSE
-
BODY_MASS
-
LEAN_BODY_MASS
-
BONE_MASS
-
BODY_FAT_PERCENTAGE
-
BODY_MASS_INDEX
-
HEIGHT
-
WAIST_CIRCUMFERENCE
-
POWER
-
SPEED
-
CYCLING_CADENCE
-
RUNNING_CADENCE
-
HYDRATION
-
DIETARY_ENERGY
-
NUTRITION
A logged food or meal carrying an arbitrary set of nutrients -- seecom.codename1.health.nutrition. Produces aNutritionSamplerather than a plain quantity, because a single entry sets many nutrient fields at once. -
SLEEP
A sleep session with optional stage detail -- seeSleepSample. -
WORKOUT
A workout or exercise session -- seeWorkoutSample. -
MINDFUL_SESSION
A mindfulness or meditation session. -
MENSTRUATION_FLOW
-
INTERMENSTRUAL_BLEEDING
-
-
Method Details
-
getId
The stable, portable identifier for this type. Safe to persist and to send to a server; also the token used by theandroid.health.readandandroid.health.writebuild hints. -
getKind
What shape of sample a query for this type returns. -
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
How this type combines over an aggregation bucket. -
isIntervalOnly
public boolean isIntervalOnly()truewhen 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.HealthStorerejects an instantaneous write of an interval-only type withHealthError.INVALID_ARGUMENT, rather than letting the platform throw something opaque later. -
forId
Looks a type up bygetId(), ornullwhen this version of the framework does not know it. Total by design -- see the class documentation. -
values
Every type known to this version of the framework. Note that a given platform supports a subset -- checkHealthStore.isTypeSupported(HealthDataType). -
toString
Description copied from class:ObjectReturns 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())
-