I want to get sleep data of previous day from Google Fit between 7pm(start time) to 11am(end time). Using following code I get the data aft
I just changed startTime and endTime and now it is working fine
Here is my doInBackground
:
protected Void doInBackground(Void... params) {
Date now = new Date();
long endTime, startTime;
int hrOfDay;
Calendar cal = Calendar.getInstance();
cal.setTime(now);
hrOfDay = cal.get(Calendar.HOUR_OF_DAY);
Log.e("hrOfDay", hrOfDay + "");
cal.set(Calendar.HOUR_OF_DAY, 19); //19 is my start time.
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.add(Calendar.DAY_OF_YEAR, -1);
startTime = cal.getTimeInMillis();
Calendar cal1 = Calendar.getInstance();
cal1.setTime(now);
cal1.set(Calendar.HOUR_OF_DAY, 11); //11 is my end time.
cal1.set(Calendar.MINUTE, 0);
cal1.set(Calendar.SECOND, 0);
endTime = cal1.getTimeInMillis();
// Begin by creating the query.
DataReadRequest readRequest1 = queryFitnessData(startTime, endTime);
DataReadResult dataReadResult1 = Fitness.HistoryApi.readData(
mClient, readRequest1).await(1, TimeUnit.MINUTES);
printData(dataReadResult1);
return null;
}