2

I am not Getting calories from Sensor API. However, sensor API is returning data for Location Sample and Steps count.

Also, is there any way of getting live data of session which is still going on?

Here is my code

                    dataSourceRequest = new DataSourcesRequest.Builder()
                            .setDataTypes( DataType.TYPE_STEP_COUNT_CUMULATIVE)
                            .setDataTypes(DataType.TYPE_LOCATION_SAMPLE)
                            .setDataTypes(DataType.TYPE_CALORIES_EXPENDED)
                            .setDataSourceTypes(DataSource.TYPE_RAW)

                            .build();


                    Fitness.getSensorsClient(MainActivity.this, account).findDataSources(dataSourceRequest).addOnSuccessListener(MainActivity.this, new OnSuccessListener<List<DataSource>>() {
                        @Override
                        public void onSuccess(List<DataSource> dataSources) {


                            for (DataSource dataSource : dataSources) {
                                Log.e(TAG, "Data source found: " + dataSource.toString());
                                Log.e(TAG, "Data Source type: " + dataSource.getDataType().getName());

                                if(dataSource.getDataType() == DataType.TYPE_LOCATION_SAMPLE) {

                                    Log.e(TAG, "Data source for LOCATION_SAMPLE found! Registering.");
                                    registerFitnessDataListener(dataSource, DataType.TYPE_LOCATION_SAMPLE);
                                }

                                if(dataSource.getDataType() == DataType.TYPE_STEP_COUNT_CUMULATIVE) {

                                    Log.e(TAG, "Data source for STEP_SAMPLE found! Registering.");
                                    registerFitnessDataListener(dataSource, DataType.TYPE_STEP_COUNT_CUMULATIVE);
                                }

                                if(dataSource.getDataType() == DataType.TYPE_CALORIES_EXPENDED) {

                                    Log.e(TAG, "Data source for CALORIE_SAMPLE found! Registering.");
                                    registerFitnessDataListener(dataSource, DataType.TYPE_CALORIES_EXPENDED);
                                }
                            }

                            Log.e(TAG, "Sensor API Enabled " + dataSources.size());
                        }
                    }).addOnFailureListener(MainActivity.this, new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {

                            Log.e(TAG, "Exception- "+e);
                        }
                    });
4

0 回答 0