简体   繁体   中英

How can i determine if the user is signed in or not , and how to sign the user out from google+ api?

I used google+ api in my android app to implement sign in with google ,When I close the sign in activity by calling finish() method, and start a new activity .

In the new activity I have a sign out button .

I want to sign him out if he clicks the button, I know the code to sign out but it seems that the code needs an object from GoogleApiClient as written below

private void signOut() {
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
        new ResultCallback<Status>() {
            @Override
            public void onResult(Status status) {
                // ...
            }
        });
}

From where I can get this object ? send it from the previous activity , initialize new one , or what should i do ?
and how to determine if the user is already signed in or not ?

Try this.

private void signOut() {
        if (mGoogleApiClient.isConnected()) {
                Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
                mGoogleApiClient.disconnect();
                mGoogleApiClient.connect();

        }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM