I've been trying for the last few days to get Sleep information from the google fit API.
I've managed to get data from the history API and the session API for the time period, but the activity list doesn't seem to include any sleep data.
I've been capturing the data in "Sleep as Android" and I've also tried "Instant". But don't see anything in the data sets coming back.
I seem to remember with the older fit app I'd see the sleep activity shown, but there's no sign of the data in the journal section of the new app.
Should I be able to get the data from the history or session data?
At the moment I'm using
DataReadRequest readRequest = new DataReadRequest.Builder()
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.read(DataType.TYPE_ACTIVITY_SEGMENT)
.build();
Fitness.getHistoryClient(this, GoogleSignIn.getLastSignedInAccount(context))
.readData(readRequest)
.addOnSuccessListener(new OnSuccessListener<DataReadResponse>(){
@Override
public void onSuccess(DataReadResponse dataReadResponse) {
List<DataSet> dataSets = dataReadResponse.getDataSets();
for (DataSet dataSet : dataSets) {
for (DataPoint dp : dataSet.getDataPoints()) {
for (Field field : dp.getDataType().getFields()){
LogUtil.d("google fit Start: " + dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)) + " " + timeFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)) + " End: " + dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)) + " " + timeFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)) + " type: " + showDataType(dp.getValue(field)));
}
}
}
}
}
I'm not sure what I'm missing to get at the correct data. I see walking, still, running etc, but just no sleep!