Enum HealthDataResolver.AggregateRequest.TimeGroupUnit

  • All Implemented Interfaces:
    Serializable, Comparable<HealthDataResolver.AggregateRequest.TimeGroupUnit>
    Enclosing interface:

    public static enum HealthDataResolver.AggregateRequest.TimeGroupUnit
    extends Enum<HealthDataResolver.AggregateRequest.TimeGroupUnit>
    This enumeration defines time units to group values of the aggregate result.
    You can retrieve grouped result of HealthDataResolver.agregate() with the specified time unit.

    Time Group Unit and Format

    The time unit for grouping can be set with HealthDataResolver.AggregateRequest.Builder.setTimeGroup(). Time information in the aggregate result is included as the following format for each time group unit.

      Time group unit Format
      MINUTELY yyyy-mm-dd hh:mm
      (e.g. 2015-10-09 18:17)
      HOURLY yyyy-mm-dd hh
      (e.g. 2015-10-09 18)
      DAILY yyyy-mm-dd
      (e.g. 2015-10-09)
      WEEKLY yyyy-ww
      (e.g. 2015-41)
      MONTHLY yyyy-mm
      (e.g. 2015-10)

    Getting Grouped Aggregate Result with Time Group Unit

    If you requests hourly average steps on today, you can set the time group unit for the aggregate request.

       public class HealthDataResolverExample {
           // The state of connection
           private HealthDataStore mStore;
           private void getHourlySteps(long startTime, long endTime) {
               HealthDataResolver resolver = new HealthDataResolver(mStore, null);
               HealthDataResolver.AggregateRequest request = new HealthDataResolver.AggregateRequest.Builder()
                   .setLocalTimeRange(HealthConstants.StepCount.START_TIME, HealthConstants.StepCount.TIME_OFFSET,
                                                                              startTime, endTime)
                       HealthConstants.StepCount.COUNT, "average")
                   .setTimeGroup(HealthDataResolver.AggregateRequest.TimeGroupUnit.HOURLY, 1,
                       HealthConstants.StepCount.TIME_OFFSET, "hour")
               try {
               } catch (Exception e) {
                   Log.d(APP_TAG, "Aggregating health data fails.");

    The retrieved result can be checked:

           private final HealthResultHolder.ResultListener<HealthDataResolver.AggregateResult> mStepAggrResult=
               new HealthResultHolder.ResultListener<HealthDataResolver.AggregateResult>() {
               public void onResult(HealthDataResolver.AggregateResult result) {
                   try {
                       Iterator<HealthData> iterator = result.iterator();
                       if (iterator.hasNext()) {
                           HealthData data =;
                           // Gets hour information as yyyy-mm-dd hh, e.g. 2015-10-09 18
                           String hour = data.getString("hour");
                           // Gets the average value for the current cursor
                           float avr = data.getFloat("average");
                           // ...
                   } finally {

    • Method Detail

      • values

        public static HealthDataResolver.AggregateRequest.TimeGroupUnit[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (HealthDataResolver.AggregateRequest.TimeGroupUnit c : HealthDataResolver.AggregateRequest.TimeGroupUnit.values())
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static HealthDataResolver.AggregateRequest.TimeGroupUnit valueOf(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        name - the name of the enum constant to be returned.
        the enum constant with the specified name
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null