Search in sources :

Example 1 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project SeriesGuide by UweTrottmann.

the class HexagonTools method checkSignInState.

private void checkSignInState() {
    if (credential.getSelectedAccount() != null && !isTimeForSignInStateCheck()) {
        Timber.d("%s: just checked state, skip", ACTION_SILENT_SIGN_IN);
    }
    lastSignInCheck = SystemClock.elapsedRealtime();
    if (googleApiClient == null) {
        googleApiClient = new GoogleApiClient.Builder(app).addApi(Auth.GOOGLE_SIGN_IN_API, getGoogleSignInOptions()).build();
    }
    android.accounts.Account account = null;
    ConnectionResult connectionResult = googleApiClient.blockingConnect();
    if (connectionResult.isSuccess()) {
        OptionalPendingResult<GoogleSignInResult> pendingResult = Auth.GoogleSignInApi.silentSignIn(googleApiClient);
        GoogleSignInResult result = pendingResult.await();
        if (result.isSuccess()) {
            GoogleSignInAccount signInAccount = result.getSignInAccount();
            if (signInAccount != null) {
                Timber.i("%s: successful", ACTION_SILENT_SIGN_IN);
                account = signInAccount.getAccount();
                credential.setSelectedAccount(account);
            } else {
                trackSignInFailure(ACTION_SILENT_SIGN_IN, "GoogleSignInAccount is null");
            }
        } else {
            trackSignInFailure(ACTION_SILENT_SIGN_IN, result.getStatus());
        }
        googleApiClient.disconnect();
    } else {
        trackSignInFailure(ACTION_SILENT_SIGN_IN, connectionResult);
    }
    boolean shouldFixAccount = account == null;
    PreferenceManager.getDefaultSharedPreferences(app).edit().putBoolean(HexagonSettings.KEY_SHOULD_VALIDATE_ACCOUNT, shouldFixAccount).apply();
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ConnectionResult(com.google.android.gms.common.ConnectionResult) GoogleSignInResult(com.google.android.gms.auth.api.signin.GoogleSignInResult)

Example 2 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project RSAndroidApp by RailwayStations.

the class SignInActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = result.getSignInAccount();
            firebaseAuthWithGoogle(account);
        } else {
            // Google Sign In failed
            Log.e(TAG, "Google Sign In failed.");
        }
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) GoogleSignInResult(com.google.android.gms.auth.api.signin.GoogleSignInResult)

Example 3 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project google-services by googlesamples.

the class RestApiActivity method handleSignInResult.

private void handleSignInResult(GoogleSignInResult result) {
    Log.d(TAG, "handleSignInResult:" + result.isSuccess());
    if (result.isSuccess()) {
        // Get the account from the sign in result
        GoogleSignInAccount account = result.getSignInAccount();
        // Signed in successfully, show authenticated UI.
        mStatusTextView.setText(getString(R.string.signed_in_fmt, account.getDisplayName()));
        updateUI(true);
        // Store the account from the result
        mAccount = account.getAccount();
        // Asynchronously access the People API for the account
        getContacts();
    } else {
        // Clear the local account
        mAccount = null;
        // Signed out, show unauthenticated UI.
        updateUI(false);
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount)

Example 4 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project quickstart-android by firebase.

the class GoogleSignInActivity method onActivityResult.

// [END on_stop_remove_listener]
// [START onactivityresult]
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = result.getSignInAccount();
            firebaseAuthWithGoogle(account);
        } else {
            // Google Sign In failed, update UI appropriately
            // [START_EXCLUDE]
            updateUI(null);
        // [END_EXCLUDE]
        }
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) GoogleSignInResult(com.google.android.gms.auth.api.signin.GoogleSignInResult)

Example 5 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project UniPool by divya21raj.

the class LoginActivity method handleSignInResult.

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);
        firebaseAuthWithGoogle(account);
    // Signed in successfully, show authenticated UI.
    } catch (ApiException e) {
        // The ApiException status code indicates the detailed failure reason.
        // Please refer to the GoogleSignInStatusCodes class reference for more information.
        Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
        Toast.makeText(getApplicationContext(), "Ok", Toast.LENGTH_SHORT).show();
        updateUI(null);
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ApiException(com.google.android.gms.common.api.ApiException)

Aggregations

GoogleSignInAccount (com.google.android.gms.auth.api.signin.GoogleSignInAccount)48 ApiException (com.google.android.gms.common.api.ApiException)15 GoogleSignInResult (com.google.android.gms.auth.api.signin.GoogleSignInResult)12 Intent (android.content.Intent)7 IOException (java.io.IOException)5 User (com.androidstudy.andelamedmanager.data.model.User)2 GoogleSignInOptions (com.google.android.gms.auth.api.signin.GoogleSignInOptions)2 Scope (com.google.android.gms.common.api.Scope)2 Request (okhttp3.Request)2 JSONException (org.json.JSONException)2 PushSocialPayload (org.wordpress.android.fluxc.store.AccountStore.PushSocialPayload)2 Context (android.content.Context)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 NonNull (androidx.annotation.NonNull)1 ServerStatusCode (cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode)1 Response (com.android.volley.Response)1 VolleyError (com.android.volley.VolleyError)1 IntentResultListener (com.codename1.impl.android.IntentResultListener)1 AccessToken (com.codename1.io.AccessToken)1