问题
I am trying to get step data from Google Fit Api. I am able to successfully connect to the Api, however when I try to retrieve data using the Fitness.HistoryApi.readData() function, it always returns status TIMEOUT and no data.
Anyone have any idea what I am doing wrong? Thanks! Code below
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
}
}
}
回答1:
I figured it out. Maybe it will help someone. I was doing this inside of an AsyncTask, and for some reason that caused it to timeout. Moving this logic outside of the AsyncTask's doInBackground method fixed the issue
来源:https://stackoverflow.com/questions/33898766/google-fit-dataread-returns-status-timeout