我需要谷歌健康阅读睡眠数据的帮助..
我有这个方法,但没有工作
private void accessGoogleFit(){
Calendar cal = Calendar.getInstance();
Date date = new Date();
cal.setTime(date);
long endTime = cal.getTimeInMillis();
cal.add(Calendar.WEEK_OF_YEAR, -1);
long startTime = cal.getTimeInMillis();
//SessionReadRequest sessionReadRequest = new SessionReadRequest.Builder().read(DataType.AGGREGATE_ACTIVITY_SUMMARY).setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS).build();
DataReadRequest dataReadRequest = new DataReadRequest.Builder().read(DataType.AGGREGATE_ACTIVITY_SUMMARY).setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS).build();
Fitness.getHistoryClient(this, GoogleSignIn.getLastSignedInAccount(this)).readData(dataReadRequest)
.addOnSuccessListener(new OnSuccessListener<DataReadResponse>() {
@Override
public void onSuccess(DataReadResponse dataReadResponse) {
List<DataSet> dataSets = dataReadResponse.getDataSets();
for(DataSet dataSet: dataSets){
for(Field field: dataSet.getDataType().getFields()){
if(field.getName().equalsIgnoreCase(FitnessActivities.SLEEP)){
Toast.makeText(MainActivity.this, "ENCONTRADO", Toast.LENGTH_LONG).show();
}
}
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
}
有人有一个能够读取睡眠数据的例子吗?