0

According to google docx we have two methods

  • SingOut
  • RevokeAccess

I need second one

For this way google provide such method

public void revokeAccess() {
    GoogleSignInOptions gso = getGoogleSignInOptions();
    mGoogleApiClient = getGoogleApiClient(gso);
    if (mGoogleApiClient.isConnected()) {
        Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
                new ResultCallback<Status>() {
                    @Override
                    public void onResult(@NonNull Status status) {
                        Logger.log(GoogleImplementation.class, "signOut:onResult:" + status, Logger.ERROR);
                    }
                });
    } else {
        Logger.log(GoogleImplementation.class, "GoogleApiClient is not connected yet.", Logger.ERROR);
    }
}

But everytime when i try to invoke it i get error

GoogleApiClient is not connected yet.

I found the same issue on stack and according to this as far as i understand i have to invoke revokeAccess() on the same object which i made LogIn()

Therefore question how i can to save this object? Or i misunderstand the consept?

What am i doing wrong?

EDIT

@NonNull
public GoogleApiClient getGoogleApiClient(GoogleSignInOptions gso) {
    return new GoogleApiClient.Builder(context)
            .enableAutoManage(activity, listenerConnection)   <-----
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
}

EDIT 2

public void revokeAccess() {
    GoogleSignInOptions gso = getGoogleSignInOptions();
    mGoogleApiClient = getGoogleApiClient(gso);
    if (mGoogleApiClient.isConnected()) {
        Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
                new ResultCallback<Status>() {
                    @Override
                    public void onResult(@NonNull Status status) {
                        Logger.log(GoogleImplementation.class, "signOut:onResult:" + status, Logger.ERROR);
                    }
                });
    } else {
        mGoogleApiClient.connect();
        Logger.log(GoogleImplementation.class, "GoogleApiClient is not connected yet.", Logger.ERROR);
        Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
                new ResultCallback<Status>() {
                    @Override
                    public void onResult(@NonNull Status status) {
                        Logger.log(GoogleImplementation.class, "signOut:onResult:" + status, Logger.ERROR);
                    }
                });
    }
}
Community
  • 1
  • 1
Sirop4ik
  • 4,543
  • 2
  • 54
  • 121

1 Answers1

0

In each different activity, You should connect your GoogleApiClient, it will not stay connected across activities.

Vickyexpert
  • 3,147
  • 5
  • 21
  • 34
Hugo Houyez
  • 470
  • 3
  • 19
  • you mean if i make log in on one activity and then i go to another one i have to make `mGoogleApiClient.connected()`? – Sirop4ik Sep 21 '16 at 08:37
  • Exactly, but you can do this using automanage thne you connect once selecting your account and after that it connect automaticcaly nothing displayed on UI. – Hugo Houyez Sep 21 '16 at 08:39
  • i edited my question. There is a line that i marked `<------` , you mean i have to use it instead of `mGoogleApiClient.connected()`? But i have already use it and still get error – Sirop4ik Sep 21 '16 at 08:49
  • look please on my edit 2. When i try invoke `revokeAccess()` method i try to check `mGoogleApiClient.isConnected()` if not i try make `mGoogleApiClient.connect();` and then again `revokeAccess` but i still get error(( What am i doing wrong? – Sirop4ik Sep 21 '16 at 08:54
  • Do you have onActivityResult and check for RC_SIGN_IN in order to perform GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); – Hugo Houyez Sep 21 '16 at 09:00
  • Then dont know why you cant connect, you have done that ? https://developers.google.com/identity/sign-in/android/start-integrating – Hugo Houyez Sep 21 '16 at 09:15
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/123841/discussion-between-hugo-houyez-and-aleksey-timoshchenko). – Hugo Houyez Sep 21 '16 at 09:19
  • yes sure i have done, i get access and i get tokenId and all are working perfect, but issue came when i try to revoke( – Sirop4ik Sep 21 '16 at 09:27