I'm using the Google Fit API on an Android phone. Subscribing to various data types and pulling the data from history works fine. I'm trying to get information about the device that recorded the data, i.e. the phone. According to the documentation, the DataSource has a getDevice() method, that returns "the device where data is being collected" - but the device is null. Why?
My code to access the device information:
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
}
}
The DataSource
you get back corresponds to the merged DataSource
for that DataType
; it'll contain DataPoints
for various origin DataSource
s.
For a given DataPoint
you can retrieve the origin DataSource
using this method (subject to the caveats in the documentation): https://developers.google.com/android/reference/com/google/android/gms/fitness/data/DataPoint#getOriginalDataSource()