我在Fitness请求中发现了一些我无法解释的奇怪行为。我并行创建了两个请求,一个是历史记录,如:
DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
.bucketByTime(1, TimeUnit.HOURS)
.enableServerQueries()
.setTimeRange(startTime, System.currentTimeMillis(), TimeUnit.MILLISECONDS)
.build();
Fitness.getHistoryClient(this, GoogleSignIn.getLastSignedInAccount(this))
.readData(readRequest) ... add listeners
而Sessions的另一个是:
SessionReadRequest request = new SessionReadRequest.Builder()
.setTimeInterval(startTime, System.currentTimeMillis(), TimeUnit.MILLISECONDS)
.read(DataType.TYPE_ACTIVITY_SEGMENT)
.readSessionsFromAllApps()
.enableServerQueries()
.build();
Fitness.getSessionsClient(this, GoogleSignIn.getLastSignedInAccount(this))
.readSession(request) ... add listeners
我的startTime
生成如下:
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.HOUR_OF_DAY, -1);
long startTime = cal.getTimeInMillis();
我在历史记录的日志中得到结果:
DataSet{d:activity.summary:gms:aggregated[
RawDataPoint{[3, 3560719, 1]@[1552377379822000000, 1552380940541000000](4,5)},
RawDataPoint{[7, 38157, 1]@[1552377341665000000, 1552377379822000000](4,5)}]}
对于会话:
Session []
我在日志中看到我在最后一小时内有两种活动类型(3 - 静止(不动)和7 - 行走)但是如何解释我在Sessions请求中没有得到它?
startTime
时,我会在Sessions请求中获得结果。