我在Android手机上使用Google Fit API。订阅各种数据类型,并从历史记录中提取数据,工作正常。我试图获取记录数据的设备,即手机的信息。根据文档,DataSource有一个getDevice()方法,该方法返回 "正在收集数据的设备"--但设备是空的。为什么会这样?
我的代码来访问设备信息。
val request = DataReadRequest.Builder()
.setTimeRange(from, to, TimeUnit.MILLISECONDS)
.enableServerQueries()
.setLimit(DATA_POINT_LIMIT)
request.read(DataType.TYPE_ACTIVITY_SEGMENT)
historyClient.readData(request.build())
.addOnSuccessListener {
data.dataSets.forEach {
//it.dataSource //Data source is not null
//it.dataSource.device //Device is null
}
}
https:/developers.google.comandroidreferencecomgoogleandroidgmsfitnessdataDataSource#getDevice()
的 DataSource
您得到的信息对应于合并后的 DataSource
为此 DataType
;它将包含 DataPoints
不同产地 DataSource
s.
对于一个给定的 DataPoint
你可以检索到的起源 DataSource
使用此方法(受文档中的注意事项限制)。https:/developers.google.comandroidreferencecomgoogleandroidgmsfitnessdataDataPoint#getOriginalDataSource()