我在创建读取请求对象 DataReadRequest 类时遇到此错误。
我确实提到了上面的问题,但它对我没有帮助,因为我没有使用上面的代码。
我看到崩溃的代码如下:
private void accessGoogleFit() {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
long endTime = cal.getTimeInMillis();
cal.add(Calendar.YEAR, -1);
long startTime = cal.getTimeInMillis();
DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();
我也提到了“https://plus.google.com/105817403737304061447/posts/5Bo6qMYRAM9”,但它也没有帮助。
以上代码直接来自“https://developers.google.com/fit/android/get-started”。
提前致谢。
最佳答案
如前所述,bucketByTime
方法(使用 .bucketByTime(1, TimeUnit.DAYS
,因为我想您想要跟踪一天的步数)根据时间段聚合数据您要求的时间,因此必须指定此分桶策略以避免抛出 IllegalStateException
。
关于java - Caused by : java. lang.IllegalStateException: 请求聚合时必须指定有效的分桶策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48709051/