public final class QuantitySample
- Object
- HealthSample
- QuantitySample
A numeric measurement with a unit – the most common kind of health sample.
QuantitySample weight = QuantitySample.create(
HealthDataType.BODY_MASS,
new HealthQuantity(72.5, HealthUnit.KILOGRAM),
System.currentTimeMillis());
weight.setRecordingMethod(RecordingMethod.MANUAL_ENTRY);
Methods
Inherited methods
Method details
create
public static QuantitySample create(HealthDataType type, HealthQuantity quantity, long instantMillis)An instantaneous measurement.
Throws
IllegalArgumentException- if the type is interval-only, such as
HealthDataType.STEPS– a step count belongs to a span of time, never to a moment.
create
public static QuantitySample create(HealthDataType type, HealthQuantity quantity, long startMillis, long endMillis)A measurement spanning an interval.
getQuantity
public HealthQuantity getQuantity()The measured value together with its unit. Read a number out of it
with
HealthQuantity.getValue(HealthUnit), which forces the unit
to be named at the call site.getValue
public double getValue(HealthUnit unit)Shorthand for
getQuantity().getValue(unit).Throws
IllegalArgumentException- if
unitmeasures a different dimension than this sample’s value.
toString
public String toString()Returns 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())