The code implemented in my application once worked, the data was inserted/displayed in Google Fit correctly, but now it doesn't work.
I have also tested the BasicHistoryApi
but it doesn't work.(https://github.com/googlesamples/android-fit)
Screenshot where this test app returns no error:
Please tell me if you use this method Fitness.HistoryApi.insertData()
and it works correctly, because I can't find any solution to make it work.
This code snippet returns "success", but no changes in my Google Fit:
DataSet runningDataSet = DataSet.create(runningDataSource);
runningDataSet.add(runningDataSet.createDataPoint().setTimeInterval(
startTime, endTime, TimeUnit.MILLISECONDS));
Session session = new Session.Builder().setName("TEST " + startTime)
.setDescription("Test description")
.setIdentifier("TEST " + " - " + startTime)
.setActivity(FitnessActivities.RUNNING_JOGGING)
.setStartTime(startTime, TimeUnit.MILLISECONDS)
.setEndTime(endTime, TimeUnit.MILLISECONDS).build();
SessionInsertRequest insertRequest = new SessionInsertRequest.Builder()
.setSession(session).addDataSet(runningDataSet).build();
Log.i(TAG, "Inserting the session in the History API");
com.google.android.gms.common.api.Status insertStatus = Fitness.SessionsApi
.insertSession(MainActivity.getFitnessClient(), insertRequest)
.await(1, TimeUnit.MINUTES);
if (!insertStatus.isSuccess()) {
Log.i(TAG, "There was a problem inserting the session: "
+ insertStatus.getStatusMessage());
Finally I have solved this issue by replacing ".setDataType(DataType.TYPE_ACTIVITY_SEGMENT)" with ".setDataType(DataType.TYPE_SPEED)" and I had to add a new permission: "addScope(new Scope(Scopes.FITNESS_LOCATION_READ_WRITE))"