I am a developer working on integrating Google Fit with a smart wearable companion app.I am exporting steps data to google fit app.It works most of the time, but randomly sometimes it doesn't work.All hourly data has been dumped into DataSet class and inserting dataset in Fitness.getHistoryClient function. DataSet object had steps for the hours and I got 200 response for the API but the data is not seen in Google Fit app.
Could someone help me?
Here is my code,
val dataSource = DataSource.Builder()
.setAppPackageName(context)
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setStreamName(TAG + AppConstants.STEPSCOUNT_FIT.value)
.setType(DataSource.TYPE_RAW)
.build()
// Create a data set
var dataSet = DataSet.create(dataSource)
dataSet = fillStepsData(dataSet)
LogHelper.i(TAG, "Inserting the dataset in the History API.")
val lastSignedInAccount = GoogleSignIn.getLastSignedInAccount(context)
return if (lastSignedInAccount != null) {
Fitness.getHistoryClient(context, lastSignedInAccount)
.insertData(dataSet)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
// At this point, the data has been inserted and can be read.
LogHelper.i(TAG, "Data insert was successful!")
readHistoryData()
} else {
LogHelper.e(
TAG,
"There was a problem inserting the dataset.",
task.exception
)
}
}
}
fillStepsData(dataSet) - this function returns DataSet.DataSet contains DataPoint which includes all hourly data.