-
-
Save ayanctech/749def6ac1ca1d44861c9816c726f333 to your computer and use it in GitHub Desktop.
Firebase - Google SignOut : Auth.GoogleSignInApi.signOut(mGoogleApiClient)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class GoogleSignOutActivity extends BaseActivityUtil { | |
| private static final String TAG = GoogleSignInActivity.class.getSimpleName(); | |
| private FirebaseAuth mAuth; | |
| private GoogleApiClient mGoogleApiClient; | |
| @Override | |
| protected void onCreate(@Nullable Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| showProgressDialog(); | |
| // GoogleSignInOptions 개체 구성 | |
| GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) | |
| .requestIdToken(getString(R.string.google_client_id)) | |
| .requestEmail() | |
| .build(); | |
| // Build a GoogleApiClient with access to the Google Sign-In API and the options specified by gso. | |
| mGoogleApiClient = new GoogleApiClient.Builder(this) | |
| .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() { | |
| @Override | |
| public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { | |
| DebugLog.logD(TAG, "Login fail"); | |
| } | |
| }) | |
| .addApi(Auth.GOOGLE_SIGN_IN_API, gso) | |
| .build(); | |
| // initialize auth | |
| mAuth = FirebaseAuth.getInstance(); | |
| signOut(); | |
| } | |
| public void signOut() { | |
| mGoogleApiClient.connect(); | |
| mGoogleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { | |
| @Override | |
| public void onConnected(@Nullable Bundle bundle) { | |
| mAuth.signOut(); | |
| if (mGoogleApiClient.isConnected()) { | |
| Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(new ResultCallback<Status>() { | |
| @Override | |
| public void onResult(@NonNull Status status) { | |
| if (status.isSuccess()) { | |
| DebugLog.logD(TAG, "User Logged out"); | |
| setResult(ResultCode.SIGN_OUT_SUCCESS); | |
| } else { | |
| setResult(ResultCode.SIGN_OUT_FAIL); | |
| } | |
| hideProgressDialog(); | |
| finish(); | |
| } | |
| }); | |
| } | |
| } | |
| @Override | |
| public void onConnectionSuspended(int i) { | |
| DebugLog.logD(TAG, "Google API Client Connection Suspended"); | |
| setResult(ResultCode.SIGN_OUT_FAIL); | |
| hideProgressDialog(); | |
| finish(); | |
| } | |
| }); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment