Dhrupal
Dhrupal

Reputation: 1873

Not able to read custom data saved of google fit server

I have successfully uploaded my custom data to google fit server. using following code.

        com.google.android.gms.common.api.Status insertStatus =
                Fitness.HistoryApi.insertData(mClient, dataSet)
                        .await(1, TimeUnit.MINUTES);
        if (!insertStatus.isSuccess()) {
            Log.i(TAG, "There was a problem inserting the dataset.");
            return null;
        }

        Log.i(TAG, "Data insert was successful!");

I found that also I can read custom data value within my app, but I am not getting it. Following is the code to retrieve it.

 final  PendingResult<DataTypeResult> pendingResult = Fitness.ConfigApi.readDataType(
                        mClient, "com.fitnessapi.custom_data_type");


                pendingResult.setResultCallback(
                        new ResultCallback<DataTypeResult>() {
                            @Override
                            public void onResult(DataTypeResult dataTypeRes) {

                                DataSet dataSet = DataSet.create(dataSource);

                                List<DataPoint> points= dataSet.getDataPoints();

                                for(int i=0; i<points.size();i++)
                                {
                                   //Never getting values
                                }
                            }
                        });
            }

Upvotes: 1

Views: 901

Answers (1)

Lewis Rhine
Lewis Rhine

Reputation: 154

The readDataType method will only return a dataType by name.

docs

Once it does you have to set a dataType variable to the results for use.

DataType dataTypeFromResult = dataTypeRes.getDataType();

Then pass it to what you need.

DataReadRequest readRequest = new DataReadRequest.Builder()
            .read(dataTypeFromResult)
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .build();

Upvotes: 3

Related Questions