title: Google Fit (Android) Get last 10 days data
body: <p>I am trying to get last 10 days data from google Fit in Android (6.0) Phone. It returns current day data correctly, but when i try to fetch data for yesterday or before that, it returns random or wrong data.</p>
  
  <pre><code>    // get the start and end date of the urrent mobile
      Calendar cal = Calendar.getInstance();
      Date now = new Date();
      cal.setTime(now);
      long endTime = cal.getTimeInMillis();
      cal.add(Calendar.DAY_OF_YEAR, -10);
      long startTime = cal.getTimeInMillis();
      java.text.DateFormat dateFormat = DateFormat.getDateInstance();
  
      //-------------steps-------------------------------
      //code to get last 10 days steps
      DataReadRequest readRequest = new DataReadRequest.Builder()
      .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
      .bucketByTime(1, TimeUnit.DAYS)
      .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
      .build();
  
      DataReadResult dataReadResult=null;
      dataReadResult = Fitness.HistoryApi.readData(mGoogleApiClient, readRequest).await(1, TimeUnit.MINUTES);
  
      // display data
      //Used for aggregated data
      if (dataReadResult.getBuckets().size() &gt; 0) {
          Log.e("History", "Number of buckets: " + dataReadResult.getBuckets().size());
          for (Bucket bucket : dataReadResult.getBuckets()) {
          List&lt;DataSet&gt; dataSets = bucket.getDataSets();
          for (DataSet dataSet : dataSets) {
              showDataSet(dataSet);
          }
          }
      }
      else if (dataReadResult.getDataSets().size() &gt; 0) //Used for non-aggregated data
      {
          Log.e("History", "Number of returned DataSets: " + dataReadResult.getDataSets().size());
          for (DataSet dataSet : dataReadResult.getDataSets()) {
          showDataSet(dataSet);
          }
      }
  </code></pre>
  
  <p>Please help me on how to get the steps of previous days. Or why am i getting wrong data.
  thanks</p>