RESULT_CANCELED error returned onActivityResult method?

305 Views Asked by At

I am trying to set up Google Fit API for a university project, however I have just noticed I am getting an error after choosing a Google log-in RESULT_CANCELED.

I have read some other forum pages and tried a few solutions:

  • Changing keystore to release mode, not debug
  • Changing dependencies
  • Changing keystore signing configs

Nothing is working for me! I have no idea what I am doing wrong so please ask me questions and I will be happy to help. I am aware I am using deprecated API functions however I cannot find anything more up to date that I understand how to implement.

Stack overflow answers researched:
Google Fit O Auth fails with RESULT_CANCELED without showing permission page
Google Oauth 2.0 RESULT_CANCELED while using Google Fit api

Builder

        mApiClient = new GoogleApiClient.Builder(this)
                .addApi(Fitness.SENSORS_API)
                .addApi(Fitness.RECORDING_API)
                .addApi(Fitness.HISTORY_API)
                .addApi(Fitness.SESSIONS_API)
                .addApi(Fitness.GOALS_API)
                .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
    }

Method

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_OAUTH) {
        authInProgress = false;
        if (resultCode == RESULT_OK) {
            if (!mApiClient.isConnecting() && !mApiClient.isConnected()) {
                mApiClient.connect();
            }
        } else if (resultCode == RESULT_CANCELED) {
            Log.e("GoogleFit", "RESULT_CANCELED");
        }
    } else {
        Log.e("GoogleFit", "requestCode NOT request_oauth");
    }
}

Configs

  release {
        storeFile file("C:\\Program Files\\Java\\jdk1.8.0_144\\bin")
        storePassword "pw"
        keyAlias "release"
        keyPassword "pw"
    }
0

There are 0 best solutions below