Interface HealthDataResolver.ReadRequest

  • Enclosing class:

    public static interface HealthDataResolver.ReadRequest
    This interface is able to make a request to read health data for the specific health data type.

    Request for Reading Data helps that your application reads Samsung Health's data.
    The following information is mandatory to build a ReadRequest instance.

    You can make a request instance with

    Reading Data Example

    You can read Samsung Health's health data with

    The filter below is created to read today's step count. The time range is set from the startTime to endTime.

       // The state of connection
       private final HealthDataStore mStore;
       public static final String APP_TAG = "MyApp";
       private static final long ONE_DAY_IN_MILLIS = 24 * 60 * 60 * 1000L;
       private long getStartTimeOfToday() {
           Calendar today = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
           today.set(Calendar.HOUR_OF_DAY, 0);
           today.set(Calendar.MINUTE, 0);
           today.set(Calendar.SECOND, 0);
           today.set(Calendar.MILLISECOND, 0);
           return today.getTimeInMillis();

    An ReadRequest instance is created by with setting the data type and the range for reading data.

       private void readTodayStepCount() {
           // Set time range from start time of today to the current time
           long startTime = getStartTimeOfToday();
           long endTime = startTime + ONE_DAY_IN_MILLIS;
           HealthDataResolver.ReadRequest request = new ReadRequest.Builder()
                   .setProperties(new String[] {HealthConstants.StepCount.COUNT})
                   .setLocalTimeRange(HealthConstants.StepCount.START_TIME, HealthConstants.StepCount.TIME_OFFSET,
                                  startTime, endTime)
                   .build(); sends a reading request to Samsung Health.
    The asynchronous request is used generally by setting a listener.

           HealthDataResolver resolver = new HealthDataResolver(mStore, null);
           try {
           } catch (Exception e) {
               Log.d(MyApp, "Getting step count fails.");

    The result is sent to the implemented listener.
    The today's total count is returned by adding all COUNT values of the result.

       private final HealthResultHolder.ResultListener<ReadResult> mListener =
               new HealthResultHolder.ResultListener<ReadResult>() {
           public void onResult(ReadResult result) {
               int count = 0;
                try {
                   Iterator<HealthData> iterator = result.iterator();
                   if (iterator.hasNext()) {
                       HealthData data =;
                       count += data.getInt(HealthConstants.StepCount.COUNT);
               } finally {