I am getting the following error when the mobile is not connected to internet while trying to build google api client to access the fit api: connection failed. Cause: ConnectionResult{statusCode=NETWORK_ERROR, resolution=null, message=null}
. I have tried two way to connect with google fit api:
METHOD 1: This one connect with Fit API after signing in. This method does not work when there is no internet. I figure internet is needed for the signin procedure.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestScopes(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE), new Scope(Scopes.FITNESS_LOCATION_READ))
.build();
return new GoogleApiClient.Builder(activity)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addConnectionCallbacks(connectionCallbacks)
.addOnConnectionFailedListener(failedListener)
.addApi(Fitness.HISTORY_API)
.addApi(Fitness.SESSIONS_API)
.addApi(Fitness.RECORDING_API)
.addApi(Fitness.SENSORS_API)
.enableAutoManage(this, 0, this)
.build();
METHOD 2: Hence I tried removing the signin feature, because I felt once the user has logged in and authorized fit api to collect data then signing in won't be essential.
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.HISTORY_API)
.addApi(Fitness.SESSIONS_API)
.addApi(Fitness.RECORDING_API)
.addApi(Fitness.SENSORS_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(failedListener)
.build();
But I am getting this error in the connection failed listener ConnectionResult{statusCode=SIGN_IN_FAILED, resolution=null, message=null}
.
How can I ensure that the fitApi can be accessed without internet connection?