title: How to get historic distance date from Google FIT in android?
body: <p>I am trying to get historic distance data of a user by passing a start time and an end time to google FIT android API.</p>
  <p>I am posting this query after checking all the related article available in stack overflow.</p>
  <pre><code>/**
   * Returns a {@link DataReadRequest}.
   */
  public DataReadRequest queryFitnessStepData(String startTime, String endTime) {
      long startVal = convertDateStringtoEpoch(startTime, true);
      long endVal = convertDateStringtoEpoch(endTime, false);
  
      DataSource datasource = new DataSource.Builder()
              .setAppPackageName(&quot;com.google.android.gms&quot;)
              .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
              .setType(DataSource.TYPE_DERIVED)
              .setStreamName(&quot;distance_delta&quot;)
              .build();
  
      return new DataReadRequest.Builder()
              .aggregate(datasource)
              .bucketByTime(1, TimeUnit.DAYS)
              .setTimeRange(startVal, endVal, TimeUnit.MILLISECONDS)
              .build();
  }
  
  private void readHistoryDistanceData(String strDate, String endDate) {
  readRequest = queryFitnessStepData(strDate, endDate);
  
  FitnessOptions fitnessOptions =
              FitnessOptions.builder()
                      .addDataType(DataType.TYPE_DISTANCE_DELTA, FitnessOptions.ACCESS_READ)
                      .addDataType(DataType.AGGREGATE_DISTANCE_DELTA, FitnessOptions.ACCESS_READ)
                      .build();
  
      if (GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount(requireActivity()), fitnessOptions)) {
          Fitness.getHistoryClient(requireActivity(), Objects.requireNonNull(GoogleSignIn.getLastSignedInAccount(requireActivity())))
                  .readData(readRequest)
                  .addOnSuccessListener(
                          new OnSuccessListener&lt;DataReadResponse&gt;() {
                              @Override
                              public void onSuccess(DataReadResponse dataReadResponse){ 
                                    //parse data
                                  }
                                }
                            }
                       }
  </code></pre>
  <p>However on running this code I am unable to get any data related to user's distance.
  I have all the permission like ACCESS_FINE_LOCATION and ACTIVITY_RECOGNITION in place.</p>
  <p>Any help would be appreciated.</p>