我目前正在开发一个使用 Google 的 Fit API 的 Android 应用程序。但是,当我从 DataReadResult 读取数据时,DataSet ds = result.getDataSet(DataType.TYPE_STEP_COUNT_DELTA);
我得到:
IllegalArgumentException: Attempting to read data for com.google.step_count.delta, which was not requested
这是我的 AsyncTask,我从中获取 DataReadResult:
public static class GetReadResultTask extends AsyncTask<Void, Void, DataReadResult> {
protected DataReadResult doInBackground(Void... voids) {
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.set(Calendar.HOUR_OF_DAY, 0);
long startTime = cal.getTimeInMillis();
DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
.bucketByTime(1, TimeUnit.HOURS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();
DataReadResult result =
Fitness.HistoryApi.readData(mClient, readRequest).await(1, TimeUnit.MINUTES);
return result;
}
}
我怎样才能解决这个问题?任何帮助,将不胜感激。