I'm developing an app for Android (only for smartphone) and I want to monitor continuous heart rate using googleApiClient (Google Fit) from smartwatch (Polar Unite fitness band).
What I have done to find data source:
/** Finds available data sources and attempts to register on a specific [DataType]. */
private fun findDataSource(){
Fitness.getSensorsClient(this, getGoogleAccount()).findDataSources(
DataSourcesRequest.Builder()
.setDataTypes(DataType.TYPE_HEART_RATE_BPM)
.setDataSourceTypes(DataSource.TYPE_RAW)
.build())
.addOnSuccessListener { dataSources ->
for (dataSource in dataSources) {
Log.i(TAG,"Data source found: $dataSource")
Log.i(TAG,"Data Source type: ${dataSource.dataType.name}")
if (dataSource.dataType == DataType.TYPE_HEART_RATE_BPM && dataPointListener == null) {
Log.i(TAG,"Data source for TYPE_HEART_RATE_BPM found!")
registerFitnessDataListener(dataSource, dataSource.dataType)
}
}
if (dataSources != null && dataSources.size == 0){
Log.i(TAG,"No data source found")
}
}
.addOnFailureListener { e -> Log.e(TAG,"failed",e) }
}
No Data Source found for heart rate
but when I change DataType to DataType.TYPE_LOCATION_SAMPLE
, it shows only my mobile phone as a data source and Missing polar watch.
Can anybody let me know the reason or where I am making mistake?