title: How to get swimming data using samsung health app
body: <p>I want to get <code>swimming</code> data from <code>Samsung Health App</code> but not get any proper solution.
  Below is my code.</p>
  
  <pre><code>    public class SwimmingReport {
  
      private final HealthDataStore mStore;
      private SwimObserver swimObserver;
      private static final long ONE_DAY_IN_MILLIS = 24 * 60 * 60 * 1000L;
  
      public SwimmingReport(HealthDataStore store) {
          mStore = store;
      }
  
      public void start(SwimObserver listener, String strDate, JSONObject jsonObject) {
          swimObserver = listener;
          HealthDataObserver.addObserver(mStore, HealthConstants.Exercise.HEALTH_DATA_TYPE, new HealthDataObserver(null) {
              @Override
              public void onChange(String s) {
                  readTodaySwimData(strDate,jsonObject);
              }
          });
  
          readTodaySwimData(strDate,jsonObject);
      }
  
      private void readTodaySwimData(String strDate,JSONObject jsonObject) {
          HealthDataResolver resolver = new HealthDataResolver(mStore, null);
          long startTime = GlobalMethods.getEpochTime(strDate);
          long endTime = startTime + ONE_DAY_IN_MILLIS;
  
          HealthDataResolver.ReadRequest request = new HealthDataResolver.ReadRequest.Builder()
                  .setDataType(HealthConstants.Exercise.HEALTH_DATA_TYPE)
                  .setProperties(new String[]{HealthConstants.Exercise.EXERCISE_TYPE})
                  .setLocalTimeRange(HealthConstants.Exercise.START_TIME, HealthConstants.Exercise.TIME_OFFSET,
                          startTime, endTime)
                  .build();
  
          try {
              resolver.read(request).setResultListener(result -&gt;{
                  double distance = 0.0;
                  try {
                      for (HealthData data : result) {
                          distance += data.getFloat(HealthConstants.Exercise.DISTANCE);
                      }
                  } finally {
                      result.close();
                  }
                  if (swimObserver != null) {
                      swimObserver.onChanged(distance,strDate,jsonObject);
                  }
              });
          } catch (Exception e) {
              Log.e("=&gt; ", "Getting step count fails.", e);
          }
      }
  
      public interface SwimObserver {
          void onChanged(Double distance, String date, JSONObject jsonObject);
      }
  
  }
  </code></pre>
  
  <p>Here is my whole source code <a href="https://github.com/sakib143/samsung-health-app-test" rel="nofollow noreferrer">this</a></p>