To insert data, you need to create a new DataSet for height and weight.
I created a method to get a DataSet with the necessary parameters for the request.
private DataSet createDataForRequest(DataType dataType, int dataSourceType, Object values, long startTime, long endTime, TimeUnit timeUnit) { DataSource dataSource = new DataSource.Builder() .setAppPackageName(mAppId) .setDataType(dataType) .setType(dataSourceType) .build(); DataSet dataSet = DataSet.create(dataSource); DataPoint dataPoint = dataSet.createDataPoint().setTimeInterval(startTime, endTime, timeUnit); if (values instanceof Integer) { dataPoint = dataPoint.setIntValues((Integer)values); } else { dataPoint = dataPoint.setFloatValues((Float)values); } dataSet.add(dataPoint); return dataSet; }
Then you need to do something like this:
DataSet weightDataSet = createDataForRequest( DataType.TYPE_WEIGHT, // for height, it would be DataType.TYPE_HEIGHT DataSource.TYPE_RAW, value, // weight in kgs startTime, // start time endTime, // end time timeUnit // Time Unit, for example, TimeUnit.MILLISECONDS ); com.google.android.gms.common.api.Status weightInsertStatus = Fitness.HistoryApi.insertData(mClient, weightDataSet ) .await(1, TimeUnit.MINUTES);
This is very useful if you are reading a Google Fit Doc . There you can read more information about data types.
Hope this helps ^^
source share