我正在尝试从Google Fit Api获取步骤数据。我能够成功连接到Api,但是当我尝试使用Fitness.HistoryApi.readData()函数检索数据时,它总是返回状态TIMEOUT而没有数据。
任何人都知道我做错了什么?谢谢!代码
private void requestHistory() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
long start = calendar.getTimeInMillis();
//Google Fit Client connection happens elswhere
if (mClient.isConnected) {
DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(start, System.currentTimeMillis(), TimeUnit.MILLISECONDS)
.enableServerQueries()
.build();
DataReadResult dataReadResult = Fitness.HistoryApi.readData(mClient, readRequest).await(1, TimeUnit.MINUTES);
//HERE dataReadResult always has status TIMEOUT and no data
if (dataReadResult.getBuckets().size() > 0) {
//do some stuff
}
}
}
答案 0 :(得分:0)
我明白了。也许它会帮助别人。我在AsyncTask中执行此操作,并且由于某种原因导致它超时。将此逻辑移到AsyncTask的doInBackground方法之外修复了问题