Java Code Examples for com.google.android.gms.auth.api.signin.GoogleSignIn#getSignedInAccountFromIntent()
The following examples show how to use
com.google.android.gms.auth.api.signin.GoogleSignIn#getSignedInAccountFromIntent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoginActivity.java From TwrpBuilder with GNU General Public License v3.0 | 9 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 1) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account); } catch (ApiException e) { Log.w("TAG", "Google sign in failed", e); // ... } } }
Example 2
Source File: SignInActivity.java From codelab-friendlychat-android with Apache License 2.0 | 8 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent in signIn() if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { // Google Sign In was successful, authenticate with Firebase GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account); } catch (ApiException e) { // Google Sign In failed, update UI appropriately Log.w(TAG, "Google sign in failed", e); } } }
Example 3
Source File: PurchaseActivity.java From YTPlayer with GNU General Public License v3.0 | 8 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account); } catch (ApiException e) { Toast.makeText(this, "Failed to sign in, Error: "+e.getStatusCode(), Toast.LENGTH_SHORT).show(); e.printStackTrace(); Log.e(TAG, "signInResult:failed code=" + e.getStatusCode()); } } if (requestCode == 104) { if (resultCode==1) { boolean isPaid = data.getBooleanExtra("payment",false); if (isPaid) { setSuccess(data.getStringExtra("client"), FirebaseDatabase.getInstance().getReference("orders")); } } } super.onActivityResult(requestCode, resultCode, data); }
Example 4
Source File: MainActivity.java From Android-9-Development-Cookbook with MIT License | 8 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { GoogleSignInAccount account = task.getResult(ApiException.class); findViewById(R.id.signInButton).setVisibility(View.GONE); Toast.makeText(this, "Logged in:"+account.getDisplayName(), Toast.LENGTH_SHORT) .show(); } catch (ApiException e) { e.printStackTrace(); Toast.makeText(this, "Sign in failed:"+e.getLocalizedMessage(), Toast.LENGTH_SHORT) .show(); } } }
Example 5
Source File: MainActivity.java From android-credentials with Apache License 2.0 | 8 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.d(TAG, "onActivityResult:" + requestCode + ":" + resultCode + ":" + data); if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); handleGoogleSignIn(task); } else if (requestCode == RC_CREDENTIALS_READ) { mIsResolving = false; if (resultCode == RESULT_OK) { Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY); handleCredential(credential); } } else if (requestCode == RC_CREDENTIALS_SAVE) { mIsResolving = false; if (resultCode == RESULT_OK) { Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show(); } else { Log.w(TAG, "Credential save failed."); } } }
Example 6
Source File: MainActivity.java From android-basic-samples with Apache License 2.0 | 8 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(intent); try { GoogleSignInAccount account = task.getResult(ApiException.class); onConnected(account); } catch (ApiException apiException) { String message = apiException.getMessage(); if (message == null || message.isEmpty()) { message = getString(R.string.signin_other_error); } onDisconnected(); new AlertDialog.Builder(this) .setMessage(message) .setNeutralButton(android.R.string.ok, null) .show(); } } }
Example 7
Source File: LoginActivity.java From triviums with MIT License | 8 votes |
@Override protected 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) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { // Google Sign In was successful, authenticate with Firebase GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account); } catch (ApiException e) { // Google Sign In failed, update UI appropriately Log.w("TAG", "Google sign in failed", e); } } }
Example 8
Source File: RNGoogleSigninModule.java From google-signin with MIT License | 7 votes |
@Override public void onActivityResult(Activity activity, final int requestCode, final int resultCode, final Intent intent) { if (requestCode == RC_SIGN_IN) { // The Task returned from this call is always completed, no need to attach a listener. Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(intent); handleSignInTaskResult(task); } else if (requestCode == REQUEST_CODE_RECOVER_AUTH) { if (resultCode == Activity.RESULT_OK) { rerunFailedAuthTokenTask(); } else { promiseWrapper.reject(MODULE_NAME, "Failed authentication recovery attempt, probably user-rejected."); } } }
Example 9
Source File: GoogleAccountsProvider.java From science-journal with Apache License 2.0 | 7 votes |
@Override public void onLoginAccountsChanged(Intent data) { try { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); GoogleSignInAccount account = task.getResult(ApiException.class); GoogleSignInAccount googleSignInAccount = GoogleSignIn.getLastSignedInAccount(context); signInCurrentAccount(googleSignInAccount); } catch (ApiException apiException) { Log.e(TAG, "GoogleSignIn api exception"); } }
Example 10
Source File: SignInActivity.java From google-services with Apache License 2.0 | 7 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...); if (requestCode == RC_SIGN_IN) { // The Task returned from this call is always completed, no need to attach // a listener. Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); handleSignInResult(task); } }
Example 11
Source File: GameSyncService.java From Passbook with Apache License 2.0 | 7 votes |
@Override public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { if(requestCode == CA.AUTH) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { mSignInAccount = task.getResult(ApiException.class); mSnapshotClient = Games.getSnapshotsClient(activity, mSignInAccount); mListener.onSyncProgress(CA.AUTH); read(); } catch (ApiException e) { mListener.onSyncFailed(CA.CONNECTION); } } }
Example 12
Source File: AndroidGoogleAccount.java From QtAndroidTools with MIT License | 7 votes |
public void signInIntentDataResult(Intent Data) { final Task<GoogleSignInAccount> SignInTask = GoogleSignIn.getSignedInAccountFromIntent(Data); if(SignInTask.isSuccessful()) { loadSignedInAccountInfo(SignInTask.getResult()); signedIn(true); } else { SignInTask.addOnCompleteListener(mActivityInstance, new SignInAccountListener()); } }
Example 13
Source File: SkeletonActivity.java From android-basic-samples with Apache License 2.0 | 7 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(intent); try { GoogleSignInAccount account = task.getResult(ApiException.class); onConnected(account); } catch (ApiException apiException) { String message = apiException.getMessage(); if (message == null || message.isEmpty()) { message = getString(R.string.signin_other_error); } onDisconnected(); new AlertDialog.Builder(this) .setMessage(message) .setNeutralButton(android.R.string.ok, null) .show(); } } else if (requestCode == RC_LOOK_AT_MATCHES) { // Returning from the 'Select Match' dialog if (resultCode != Activity.RESULT_OK) { logBadActivityResult(requestCode, resultCode, "User cancelled returning from the 'Select Match' dialog."); return; } TurnBasedMatch match = intent .getParcelableExtra(Multiplayer.EXTRA_TURN_BASED_MATCH); if (match != null) { updateMatch(match); } Log.d(TAG, "Match = " + match); } else if (requestCode == RC_SELECT_PLAYERS) { // Returning from 'Select players to Invite' dialog if (resultCode != Activity.RESULT_OK) { // user canceled logBadActivityResult(requestCode, resultCode, "User cancelled returning from 'Select players to Invite' dialog"); return; } // get the invitee list ArrayList<String> invitees = intent .getStringArrayListExtra(Games.EXTRA_PLAYER_IDS); // get automatch criteria Bundle autoMatchCriteria; int minAutoMatchPlayers = intent.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0); int maxAutoMatchPlayers = intent.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0); if (minAutoMatchPlayers > 0) { autoMatchCriteria = RoomConfig.createAutoMatchCriteria(minAutoMatchPlayers, maxAutoMatchPlayers, 0); } else { autoMatchCriteria = null; } TurnBasedMatchConfig tbmc = TurnBasedMatchConfig.builder() .addInvitedPlayers(invitees) .setAutoMatchCriteria(autoMatchCriteria).build(); // Start the match mTurnBasedMultiplayerClient.createMatch(tbmc) .addOnSuccessListener(new OnSuccessListener<TurnBasedMatch>() { @Override public void onSuccess(TurnBasedMatch turnBasedMatch) { onInitiateMatch(turnBasedMatch); } }) .addOnFailureListener(createFailureListener("There was a problem creating a match!")); showSpinner(); } }
Example 14
Source File: SignInActivity.java From budgetto with MIT License | 7 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account); } catch (ApiException e) { e.printStackTrace(); hideProgressView(); loginError("Google sign in failed."); } } }
Example 15
Source File: AuthenticationManager.java From ground-android with Apache License 2.0 | 7 votes |
private void onActivityResult(ActivityResult activityResult) { // The Task returned from getSignedInAccountFromIntent is always completed, so no need to // attach a listener. try { Task<GoogleSignInAccount> googleSignInTask = GoogleSignIn.getSignedInAccountFromIntent(activityResult.getData()); onGoogleSignIn(googleSignInTask.getResult(ApiException.class)); } catch (ApiException e) { Log.w(TAG, "Sign in failed: " + e); signInState.onNext(new SignInState(e)); } }
Example 16
Source File: BaseDemoActivity.java From android-samples with Apache License 2.0 | 7 votes |
/** * Handles resolution callbacks. */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case REQUEST_CODE_SIGN_IN: if (resultCode != RESULT_OK) { // Sign-in may fail or be cancelled by the user. For this sample, sign-in is // required and is fatal. For apps where sign-in is optional, handle // appropriately Log.e(TAG, "Sign-in failed."); finish(); return; } Task<GoogleSignInAccount> getAccountTask = GoogleSignIn.getSignedInAccountFromIntent(data); if (getAccountTask.isSuccessful()) { initializeDriveClient(getAccountTask.getResult()); } else { Log.e(TAG, "Sign-in failed."); finish(); } break; case REQUEST_CODE_OPEN_ITEM: if (resultCode == RESULT_OK) { DriveId driveId = data.getParcelableExtra( OpenFileActivityOptions.EXTRA_RESPONSE_DRIVE_ID); mOpenItemTaskSource.setResult(driveId); } else { mOpenItemTaskSource.setException(new RuntimeException("Unable to open file")); } break; } super.onActivityResult(requestCode, resultCode, data); }
Example 17
Source File: SettingsFragment.java From YTPlayer with GNU General Public License v3.0 | 7 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode==103) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account); } catch (ApiException e) { Toast.makeText(activity, "Failed to sign in, Error: "+e.getStatusCode(), Toast.LENGTH_SHORT).show(); e.printStackTrace(); Log.e(TAG, "signInResult:failed code=" + e.getStatusCode()); } } super.onActivityResult(requestCode, resultCode, data); }
Example 18
Source File: GoogleProvider.java From SEAL-Demo with MIT License | 7 votes |
/** * Handle Activity Result for Google login * @param requestCode Request code * @param resultCode Actual result code from the request * @param data Additional data from the result */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // The Task returned from this call is always completed, no need to attach a listener. Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); if (resultCode == Activity.RESULT_OK) { handleSignInResult(task); } else { Log.e(TAG, "Sign in error: ", task.getException()); } }
Example 19
Source File: GoogleSignInActivity.java From wear-os-samples with Apache License 2.0 | 7 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.d(TAG, "Activity request code: " + requestCode); // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); if (requestCode == REQUEST_CODE_SIGN_IN) { // The Task returned from this call is always completed, no need to attach // a listener. Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); handleSignInResult(task); } }
Example 20
Source File: SignInActivityWithDrive.java From google-services with Apache License 2.0 | 7 votes |
@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) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); handleSignInResult(task); } }