I am getting this error from google fit api. It doesnt happens every time but if i get this error then i couldnt get my step data until i uninstall the app. I configured OAuth 2.0 client auth for my app correctly. But sometimes still I am getting this error
"com.google.android.gms.common.api.ApiException: 8: The connection to Google Play services was lost"
when I investigate it from google document it says me that:
https://developers.google.com/android/reference/com/google/android/gms/common/api/CommonStatusCodes public static final int INTERNAL_ERROR
As the document says when i try to connect googlefit on the onfailure method then nothimg happens and still facing this problem.
An internal error occurred. Retrying should resolve the problem. Constant Value: 8
here is the code block and sometimes the onfailure method is triggering
DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();
Fitness.getHistoryClient(MainActivity.activity, GoogleSignIn.getLastSignedInAccount(MainActivity.activity))
.readData(readRequest)
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Crashlytics.log(Log.ASSERT, "fail :", e.toString());
}
})
.addOnSuccessListener(new OnSuccessListener<DataReadResponse>()
{
@Override
public void onSuccess(DataReadResponse dataReadResponse)
{
for (Bucket bucket : dataReadResponse.getBuckets())
{
for (DataSet dataSet : bucket.getDataSets())
{
for (DataPoint dataPoint : dataSet.getDataPoints())
{
User.current().userFitnessData.totalDistance = dataPoint.getValue(dataPoint.getDataType().getFields().get(0)).asFloat();
}
}
}
Crashlytics.log(Log.ASSERT, "Todays Steps", User.current().userFitnessData.getTodaysSteps() + "");
if (callBack != null)
callBack.onDistanceDataReceived();
}
});