目录

ReadOptions

Class Info

public class ReadOptions

Request class for reading data. The request can be used to specify the type of data to be read and grouped parameters. The read request requires the setting of a time range and allows data to be read in detail or summary mode.

When constructing a ReadOptions object to read detailed data, you must specify the time range for the data, and specify one or more DataType or DataCollector objects as needed.

Sample code for building a ReadOptions object to read detailed data:

  1. Build ReadOptions to read the detailed data of a specified DataType (DT_CONTINUOUS_STEPS_DELTA).
    The sample code is as follows:
    Java
    ReadOptions readOptions = new ReadOptions.Builder()
        .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
        .read(DataType.DT_CONTINUOUS_STEPS_DELTA)
        .build();
    Kotlin
    val readOptions = ReadOptions.Builder()
        .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
        .read(DataType.DT_CONTINUOUS_STEPS_DELTA)
        .build()
  2. Build ReadOptions to read the detailed data of multiple specified DataType objects (DT_CONTINUOUS_STEPS_DELTA and DT_INSTANTANEOUS_HEIGHT).
    The sample code is as follows:
    Java
    ReadOptions readOptions = new ReadOptions.Builder()
        .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
        .read(DataType.DT_CONTINUOUS_STEPS_DELTA)
        .read(DataType.DT_INSTANTANEOUS_HEIGHT)
        .build();
    Kotlin
    val readOptions = ReadOptions.Builder()
        .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
        .read(DataType.DT_CONTINUOUS_STEPS_DELTA)
        .read(DataType.DT_INSTANTANEOUS_HEIGHT)
        .build()
  3. Build ReadOptions to read the detailed data from the specified DataCollector.
    The sample code is as follows:
    Java
    ReadOptions readOptions = new ReadOptions.Builder()
        .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
        .read(dataCollectorDevices)
        .build();
    Kotlin
    val readOptions = ReadOptions.Builder()
        .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
        .read(dataCollectorDevices)
        .build()

Build ReadOptions to read summary data by specifying the time range, summary mode, and grouping mode. These three options are mandatory.

Sample code for building ReadOptions to read summary data:
Java
ReadOptions readOptions = new ReadOptions.Builder()
    .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
    .polymerize(DataType.DT_CONTINUOUS_STEPS_DELTA, DataType.DT_CONTINUOUS_STEPS_TOTAL)
    .groupByTime(1, TimeUnit.HOURS)
    .build();
Kotlin
val readOptions = ReadOptions.Builder()
    .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
    .polymerize(DataType.DT_CONTINUOUS_STEPS_DELTA, DataType.DT_CONTINUOUS_STEPS_TOTAL)
    .groupByTime(1, TimeUnit.HOURS)
    .build()
  1. The start time and end time for querying the activity and health data must be later than the UNIX timestamp corresponding to January 1, 2014.
  2. The start time and end time for querying cannot span over 31 days.

Nested Class Summary

Qualifier and Type

Class Name and Description

public static class

ReadOptions.Builder

Builder for ReadOptions.

Constant Summary

Type

Name

Description

int

NO_LIMIT

Indicates that there is no limit for the returned data amount.

Public Method Summary

Qualifier and Type

Method Name and Description

List<DataCollector>

getDataCollectors()

Obtains the data collectors for data reading.

List<DataType>

getDataTypes()

Obtains the data types for data reading.

long

getEndTime(TimeUnit timeUnit)

Obtains the end time of the target data.

long

getGroupPeriod(TimeUnit timeUnit)

Obtains the group period.

int

getGroupType()

Obtains the group type.

int

getPageSize()

Obtains the maximum number of pages for the paginated query results.

List<DataCollector>

getPolymerizedDataCollectors()

Obtains the polymerized data collectors.

List<DataType>

getPolymerizedDataTypes()

Obtains the polymerized data types.

long

getStartTime(TimeUnit timeUnit)

Obtains the start time of the target data.

Constants

[h2]NO_LIMIT

Constant

public static final int NO_LIMIT

Indicates that the returned results are not paginated. Constant value: 0

Public Methods

[h2]getDataCollectors()

Method

public List<DataCollector> getDataCollectors()

Obtains the data collectors for data reading.

Returns

Type

Description

List<DataCollector>

Data collectors for data reading.

[h2]getDataTypes()

Method

public List<DataType> getDataTypes()

Obtains the data types for data reading.

Returns

Type

Description

List<DataType>

Data types for data reading.

[h2]getEndTime(TimeUnit timeUnit)

Method

public long getEndTime(TimeUnit timeUnit)

Obtains the end time of the target data.

Parameters

Name

Description

timeUnit

Time unit.

Returns

Type

Description

long

End time in a specified time unit.

[h2]getGroupPeriod(TimeUnit timeUnit)

Method

public long getGroupPeriod(TimeUnit timeUnit)

Obtains the group period.

Parameters

Name

Description

timeUnit

Time unit.

Returns

Type

Description

long

Duration for grouping.

[h2]getGroupType()

Method

public int getGroupType()

Obtains the group type.

Returns

Type

Description

int

Group type.

[h2]getPageSize()

Method

public int getPageSize()

Obtains the maximum number of pages for the paginated query results.

Returns

Type

Description

int

Maximum number of pages for the paginated query results.

[h2]getPolymerizedDataCollectors()

Method

public List<DataCollector> getPolymerizedDataCollectors()

Obtains the polymerized data collectors.

Returns

Type

Description

List<DataCollector>

Polymerized data collectors.

[h2]getPolymerizedDataTypes()

Method

public List<DataType> getPolymerizedDataTypes()

Obtains the polymerized data types.

Returns

Type

Description

List<DataType>

Polymerized data types.

[h2]getStartTime(TimeUnit timeUnit)

Method

public long getStartTime(TimeUnit timeUnit)

Obtains the start time of the target data.

Parameters

Name

Description

timeUnit

Time unit.

Returns

Type

Description

long

Start time in a specified time unit.