public abstract class HealthSample
- Object
- HealthSample
Known subtypesBloodPressureSample, CategorySample, QuantitySample, SeriesSample, SessionSample
The base of every health record: what it measures and when.
Concrete subclasses correspond to HealthDataKind –
QuantitySample, CategorySample, SeriesSample and the
SessionSample family.
Instants and intervals
Every sample carries both a start and an end. When they are equal the
sample marks an instant – see isInstantaneous(). Cumulative types
such as steps are always intervals; see
HealthDataType.isIntervalOnly().
Identity
getId() is assigned by the platform on write. It is scoped to this
platform and this installation and does not survive a reinstall, so
it must not be used as a primary key on your server.
getMetadata() is not persisted to HealthKit or Health Connect in
this release. It round-trips through the local store used by the
simulator, desktop and JavaScript, and it travels with a sample you
hold in memory, but a sample written to a mobile platform and read back
comes back without it. Health Connect has no arbitrary metadata –
only a single clientRecordId – so a general map cannot be carried
there at all. Correlate on your own identifier held in your own
storage, keyed by whatever you can reconstruct from the sample’s type,
time range and value.
Mutability
Samples you build for a write are mutable so optional fields can be
filled in before handing them to HealthStore. Samples returned from a
query are snapshots: changing one does not change the store, and to
modify stored data you delete and re-write it.
Constructors
protected HealthSample(HealthDataType type, long startMillis, long endMillis) | Creates a sample spanning [startMillis, endMillis]. |
Methods
Inherited methods
Constructor details
HealthSample
protected HealthSample(HealthDataType type, long startMillis, long endMillis)[startMillis, endMillis].Throws
IllegalArgumentException- if
typeis null or the end precedes the start.
Method details
getType
public final HealthDataType getType()getStartMillis
public final long getStartMillis()getEndMillis
public final long getEndMillis()getStart
public final Instant getStart()When this sample starts.
The millis accessors stay, and are what the ports and the wire format
use: a series can hold tens of thousands of measurements and an
Instant per point is an allocation per point. For a single sample
this is the type the rest of the framework speaks –
com.codename1.calendar included – so it is what the public API
hands out.
getEnd
public final Instant getEnd()getStart() for an instantaneous
sample.getDuration
public final Duration getDuration()isInstantaneous
public final boolean isInstantaneous()true when this sample marks a moment rather than a span.getDurationMillis
public final long getDurationMillis()getId
public final String getId()setId
public final void setId(String id)getSource
public final HealthSource getSource()setSource
public final void setSource(HealthSource source)getRecordingMethod
public final RecordingMethod getRecordingMethod()RecordingMethod.UNKNOWN.setRecordingMethod
public final void setRecordingMethod(RecordingMethod recordingMethod)getMetadata
public final Map<String, String> getMetadata()Free-form metadata carried alongside the sample, never null.
Not a place for a correlation identifier, tempting as it
looks. It round-trips through the local and simulator stores but
is not written to HealthKit or Health Connect in this release, so
on a phone it is gone the moment the sample is read back – and
getId() is no substitute either, being platform-assigned and
unstable across a reinstall. Keep the identifier in your own
storage and correlate on that.
putMetadata
public final void putMetadata(String key, String value)equals
public boolean equals(Object o)hashCode
public int hashCode()toString
public String toString()