HealthService Data Types

HealthService defines and uses several data types.

WeightRecord 

An object representing a single body-weight measurement.

Property NameTypeDescriptionExample
valueNumberThe weight measurement, expressed in unit. On a write, the value must be greater than 0.80.5
unitWeightUnitThe unit that value is expressed in."kg"
startTimeNumberThe time that the measurement was taken, in epoch milliseconds (UTC). On a write, defaults to the current time when omitted.1721990400000
endTimeNumberThe end time for the measurement, in epoch milliseconds (UTC). null for an instantaneous measurement.null

GetWeightOptions 

An object representing the options for a getWeight() request. All properties are optional. Pass null for the entire object to use the defaults.

Property NameTypeDescriptionExample
startTimeNumberThe earliest time to read records from, in epoch milliseconds (UTC). null means no lower bound.null
endTimeNumberThe latest time to read records to, in epoch milliseconds (UTC). null means the current time.null
limitNumberThe maximum number of records to return. null means no limit, subject to a soft cap.10
preferredUnitWeightUnitThe unit that the returned value of each record is expressed in. The device’s health store records weight without a unit, so HealthService converts to this unit. null defaults to "kg"."kg"

WeightUnit 

A string value that represents the unit for a weight measurement.

ValueDescription
"kg"Kilograms.
"lbs"Pounds.

HealthServiceFailure 

An object representing an error that occurred when accessing HealthService features.

Property NameTypeDescription
codeHealthServiceFailureCodeA value representing the reason for a health data error. Possible failure codes include the following:
  • SERVICE_NOT_ENABLED
  • USER_DENIED_PERMISSION
  • PROVIDER_NOT_INSTALLED (Android only)
  • PROVIDER_UPDATE_REQUIRED (Android only)
  • UNKNOWN_REASON
messageStringA string value describing the reason for the failure. This value is suitable for use in user interface messages. The message is provided in English, and isn’t localized.