Develop Secure Code
HealthService Data Types
getHealthService()
isAvailable()
getWeight(options)
writeWeight(record)
HealthService defines and uses several data types.
An object representing a single body-weight measurement.
| Property Name | Type | Description | Example |
|---|---|---|---|
value | Number | The weight measurement, expressed in unit. On a write, the value must be greater than 0. | 80.5 |
unit | WeightUnit | The unit that value is expressed in. | "kg" |
startTime | Number | The time that the measurement was taken, in epoch milliseconds (UTC). On a write, defaults to the current time when omitted. | 1721990400000 |
endTime | Number | The end time for the measurement, in epoch milliseconds (UTC). null for an instantaneous measurement. | null |
An object representing the options for a getWeight() request. All properties are optional. Pass null for the entire object to use the defaults.
| Property Name | Type | Description | Example |
|---|---|---|---|
startTime | Number | The earliest time to read records from, in epoch milliseconds (UTC). null means no lower bound. | null |
endTime | Number | The latest time to read records to, in epoch milliseconds (UTC). null means the current time. | null |
limit | Number | The maximum number of records to return. null means no limit, subject to a soft cap. | 10 |
preferredUnit | WeightUnit | The 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" |
A string value that represents the unit for a weight measurement.
| Value | Description |
|---|---|
"kg" | Kilograms. |
"lbs" | Pounds. |
An object representing an error that occurred when accessing HealthService features.
| Property Name | Type | Description |
|---|---|---|
code | HealthServiceFailureCode | A value representing the reason for a health data error. Possible failure codes include the following:
|
message | String | A 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. |