Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.
This repository was archived by the owner on Jul 8, 2025. It is now read-only.

Find Data Source Using Sensor API #61

@ankit-geeky

Description

@ankit-geeky

I am using the below code to find data sources because I am interested in reading data specifically from the sensor on a wearable device but not from the same type of sensor on the phone.

private fun findDataSource(){
Fitness.getSensorsClient(this, getGoogleAccount()).findDataSources(
DataSourcesRequest.Builder()
.setDataTypes(DataType.TYPE_LOCATION_SAMPLE)
.setDataSourceTypes(DataSource.TYPE_RAW)
.build())
.addOnSuccessListener { dataSources ->
/**
* Only my mobile phone was found as a data source
* Missing android watch
*/
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) }
}

But from the above code
* Only my mobile phone was found as a data source
* Missing android watch

NOTE: Using Polar Unite Fitness Watch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions