1

I'm developing an app for Android (only for smartphone, not for wear) and I want to get the heart rate using googleApiClient (Google Fit) from smartwatch (Huawei Watch f.e.). I tried using Sensor API but wear is not listed as DataSource in Google Fit API.

REQUEST_INTERVAL = 5;  
Fitness.SensorsApi.findDataSources(client, new DataSourcesRequest.Builder()
                .setDataTypes(DataType.TYPE_LOCATION_SAMPLE,
                        DataType.TYPE_STEP_COUNT_CUMULATIVE,
                        DataType.TYPE_DISTANCE_DELTA,
                        DataType.TYPE_HEART_RATE_BPM)
                .setDataSourceTypes(DataSource.TYPE_RAW, DataSource.TYPE_DERIVED)
                .build())
                .setResultCallback(new ResultCallback<DataSourcesResult>() {
                    @Override
                    public void onResult(DataSourcesResult dataSourcesResult) {

                        for (DataSource dataSource : dataSourcesResult.getDataSources()) {
                            // There isn't heart rate source here
                            final DataType dataType = dataSource.getDataType();
                            Fitness.SensorsApi.add(client,
                                    new SensorRequest.Builder()
                                            .setDataSource(dataSource)
                                            .setDataType(dataType)
                                            .setSamplingRate(REQUEST_INTERVAL, TimeUnit.SECONDS)
                                            .build(),
                                    listener)
                                    .setResultCallback(new ResultCallback<Status>() {
                                        @Override
                                        public void onResult(Status status) {
                                            ...
                                        }
                                    });
                            }
                        }
                    }
                });

Othrer data(like steps, location and distance) are came. My client:

googleApiClient = new GoogleApiClient.Builder(activity)
                .addApi(Plus.API)
                .addApi(Fitness.RECORDING_API)
                .addApi(Fitness.HISTORY_API)
                .addApi(Fitness.SENSORS_API)
                .addApi(LocationServices.API)
                .addApi(Fitness.BLE_API)
                .addScope(Plus.SCOPE_PLUS_LOGIN)
                .addScope(Plus.SCOPE_PLUS_PROFILE)
                .addScope(new Scope(Scopes.PROFILE))
                .addScope(new Scope(Scopes.PLUS_LOGIN))
                .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
                .addScope(new Scope(Scopes.FITNESS_BODY_READ))
                .addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

I spent some hours reading docs and answers but can't find a solution. Maybe I do something wrong. Data from smartphone came, but from wear it doesn't. Google fit is installed on wear.

Thanks for your answer!

abielita
  • 12,126
  • 2
  • 15
  • 52
Devnock
  • 253
  • 2
  • 15
  • Did you try to sync your wearable device to your mobile device? – Ultraman Mar 28 '19 at 03:31
  • @Ultraman it was a long time ago, so actually I even don't remember the problem, but if I'm not mistaken - yes wearable device was always synced and paired with a smartphone – Devnock Mar 28 '19 at 19:55
  • @Devnock, did you manage to resolve this? I'm hitting the issue as yours. The watch and phone are paired, I could see my watch in Wearable.NodeApi.getConnectedNodes(mGoogleApiClient). But the watch is not listed in the data source. – djreenykev Nov 09 '19 at 07:28

0 Answers0