0

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?

suku
  • 10,507
  • 16
  • 75
  • 120

1 Answers1

0

Try the following workaround:

  • Check that your project has a product name and an email address associated with it, both to be found in the "consent screen" section.
  • If it doesn't work, delete the project and re-create it.
  • Based from this thread, this issue occurs if app is not registered properly in google developer console.

I think you have registered app on Google developer Console using production keystore certificate fingerprint(SHA1) where as you are testing it on app which has debug keystore.

Perform following steps:

  1. Create one more client Id using debug keystore certificate fingerprint(SHA1).
  2. Uninstall existing app.
  3. Install app & connect to Google fit.
  4. Check under google fit app & make sure that your app is listed as a connected app (... > Settings > Connected apps > Connected apps & devices).
  5. Now run the above code & it will work !!!

Check these related tickets:

Hope this helps!

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59