Java Code Examples for com.google.android.gms.auth.api.signin.GoogleSignIn#getLastSignedInAccount()

The following examples show how to use com.google.android.gms.auth.api.signin.GoogleSignIn#getLastSignedInAccount() . 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: SignInActivityWithDrive.java    From google-services with Apache License 2.0 10 votes vote down vote up
@Override
public void onStart() {
    super.onStart();

    // Check if the user is already signed in and all required scopes are granted
    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
    if (account != null && GoogleSignIn.hasPermissions(account, new Scope(Scopes.DRIVE_APPFOLDER))) {
        updateUI(account);
    } else {
        updateUI(null);
    }
}
 
Example 2
Source File: GoogleAccountsProvider.java    From science-journal with Apache License 2.0 9 votes vote down vote up
public GoogleAccountsProvider(Context context) {
  super(context);
  this.context = context;
  setShowSignInActivityIfNotSignedIn(false);
  GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
      .requestEmail()
      .build();
  googleSignInClient = GoogleSignIn.getClient(context, gso);

  GoogleSignInAccount googleSignInAccount = GoogleSignIn.getLastSignedInAccount(context);
  if (googleSignInAccount != null) {
    signInCurrentAccount(googleSignInAccount);
  }
}
 
Example 3
Source File: Manager.java    From react-native-fitness with MIT License 9 votes vote down vote up
public void subscribeToSteps(Context context, final Promise promise){
    final GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(context);
    if(account == null){
        promise.resolve(false);
        return;
    }
    Fitness.getRecordingClient(context, account)
            .subscribe(DataType.TYPE_STEP_COUNT_DELTA)
            .addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    promise.resolve(true);
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    promise.resolve(false);
                }
            });
}
 
Example 4
Source File: EventsController.java    From PGSGP with MIT License 9 votes vote down vote up
public void loadEvents() {
    GoogleSignInAccount googleSignInAccount = GoogleSignIn.getLastSignedInAccount(activity);
    if (connectionController.isConnected().first && googleSignInAccount != null) {
        Games.getEventsClient(activity, googleSignInAccount)
                .load(true)
                .addOnCompleteListener(new OnCompleteListener<AnnotatedData<EventBuffer>>() {
                    @Override
                    public void onComplete(@NonNull Task<AnnotatedData<EventBuffer>> task) {
                        if (task.isSuccessful() && task.getResult() != null) {
                            EventBuffer events = task.getResult().get();
                            if (events != null) {
                                JSONArray jsonArray = new JSONArray();
                                for (Event event : events) {
                                    jsonArray.put(eventInfoArray(event));
                                }
                                godotCallbacksUtils.invokeGodotCallback(GodotCallbacksUtils.EVENTS_LOADED, new Object[]{jsonArray.toString()});
                            } else {
                                godotCallbacksUtils.invokeGodotCallback(GodotCallbacksUtils.EVENTS_EMPTY, new Object[]{});
                            }
                        } else {
                            godotCallbacksUtils.invokeGodotCallback(GodotCallbacksUtils.EVENTS_LOADED_FAILED, new Object[]{});
                        }
                    }
                });
    } else {
        godotCallbacksUtils.invokeGodotCallback(GodotCallbacksUtils.EVENTS_LOADED_FAILED, new Object[]{});
    }
}
 
Example 5
Source File: EventsController.java    From PGSGP with MIT License 9 votes vote down vote up
public void submitEvent(String eventId, int incrementBy) {
    GoogleSignInAccount googleSignInAccount = GoogleSignIn.getLastSignedInAccount(activity);
    if (connectionController.isConnected().first && googleSignInAccount != null) {
        Games.getEventsClient(activity, googleSignInAccount).increment(eventId, incrementBy);
        godotCallbacksUtils.invokeGodotCallback(GodotCallbacksUtils.EVENT_SUBMITTED, new Object[]{eventId});
    } else {
        godotCallbacksUtils.invokeGodotCallback(GodotCallbacksUtils.EVENT_SUBMITTED_FAILED, new Object[]{eventId});
    }
}
 
Example 6
Source File: GameSyncService.java    From Passbook with Apache License 2.0 9 votes vote down vote up
@Override
public SyncService initialize(Activity context) {
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
            .requestScopes(Drive.SCOPE_APPFOLDER)
            //.requestScopes(Games.SCOPE_GAMES)
            .build();
    mGoogleSignClient = GoogleSignIn.getClient(context, gso);
    mSignInAccount = GoogleSignIn.getLastSignedInAccount(context);
    return this;
}
 
Example 7
Source File: RestApiActivity.java    From google-services with Apache License 2.0 9 votes vote down vote up
@Override
public void onStart() {
    super.onStart();

    // Check if the user is already signed in and all required scopes are granted
    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
    if (GoogleSignIn.hasPermissions(account, new Scope(CONTACTS_SCOPE))) {
        updateUI(account);
    } else {
        updateUI(null);
    }
}
 
Example 8
Source File: AchievementsController.java    From PGSGP with MIT License 9 votes vote down vote up
public void incrementAchievement(String achievementName, int step) {
    GoogleSignInAccount googleSignInAccount = GoogleSignIn.getLastSignedInAccount(activity);
    if (connectionController.isConnected().first && googleSignInAccount != null) {
        Games.getAchievementsClient(activity, googleSignInAccount).increment(achievementName, step);
        godotCallbacksUtils.invokeGodotCallback(GodotCallbacksUtils.ACHIEVEMENT_INCREMENTED, new Object[]{achievementName});
    } else {
        godotCallbacksUtils.invokeGodotCallback(GodotCallbacksUtils.ACHIEVEMENT_INCREMENTED_FAILED, new Object[]{achievementName});
    }
}
 
Example 9
Source File: GoogleFitModule.java    From react-native-google-fitness with MIT License 8 votes vote down vote up
@ReactMethod
public void hasPermissions(String fitnessOptionJsonStr, Promise promise) {
    if (GoogleSignIn.getLastSignedInAccount(mReactContext) == null) {
        promise.resolve(false);
        return;
    }

    try {
        FitnessOptions fitnessOptions = (FitnessOptions) StatementFactory
                .fromJson(fitnessOptionJsonStr)
                .execute(new JavaContext(), null);
        promise.resolve(GoogleSignIn.hasPermissions(getLastSignedInAccountSafely(), fitnessOptions));
    } catch (Exception e) {
        Log.e(TAG, "Failed to create FitnessOptions", e);
        promise.reject(e);
    }
}
 
Example 10
Source File: ConnectionController.java    From PGSGP with MIT License 8 votes vote down vote up
public Pair<Boolean, String> isConnected() {
    GoogleSignInAccount googleSignInAccount = GoogleSignIn.getLastSignedInAccount(activity);
    
    String accId = "";
    if (googleSignInAccount != null && googleSignInAccount.getId() != null) {
        accId = googleSignInAccount.getId();
    }
    return new Pair<>(GoogleSignIn.hasPermissions(googleSignInAccount, signInOptions.getScopeArray()), accId);
}
 
Example 11
Source File: SignInActivity.java    From google-services with Apache License 2.0 8 votes vote down vote up
@Override
public void onStart() {
    super.onStart();

    // [START on_start_sign_in]
    // Check for existing Google Sign In account, if the user is already signed in
    // the GoogleSignInAccount will be non-null.
    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
    updateUI(account);
    // [END on_start_sign_in]
}
 
Example 12
Source File: BaseDemoActivity.java    From android-samples with Apache License 2.0 8 votes vote down vote up
/**
 * Starts the sign-in process and initializes the Drive client.
 */
protected void signIn() {
    Set<Scope> requiredScopes = new HashSet<>(2);
    requiredScopes.add(Drive.SCOPE_FILE);
    requiredScopes.add(Drive.SCOPE_APPFOLDER);
    GoogleSignInAccount signInAccount = GoogleSignIn.getLastSignedInAccount(this);
    if (signInAccount != null && signInAccount.getGrantedScopes().containsAll(requiredScopes)) {
        initializeDriveClient(signInAccount);
    } else {
        GoogleSignInOptions signInOptions =
                new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                  .requestScopes(Drive.SCOPE_FILE)
                  .requestScopes(Drive.SCOPE_APPFOLDER)
                  .build();
        GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(this, signInOptions);
        startActivityForResult(googleSignInClient.getSignInIntent(), REQUEST_CODE_SIGN_IN);
    }
}
 
Example 13
Source File: AchievementsController.java    From PGSGP with MIT License 7 votes vote down vote up
public void unlockAchievement(String achievementName) {
    GoogleSignInAccount googleSignInAccount = GoogleSignIn.getLastSignedInAccount(activity);
    if (connectionController.isConnected().first && googleSignInAccount != null) {
        Games.getAchievementsClient(activity, googleSignInAccount).unlock(achievementName);
        godotCallbacksUtils.invokeGodotCallback(GodotCallbacksUtils.ACHIEVEMENT_UNLOCKED, new Object[]{achievementName});
    } else {
        godotCallbacksUtils.invokeGodotCallback(GodotCallbacksUtils.ACHIEVEMENT_UNLOCKED_FAILED, new Object[]{achievementName});
    }
}
 
Example 14
Source File: GoogleProviderHandler.java    From capacitor-firebase-auth with MIT License 7 votes vote down vote up
@Override
public void fillResult(AuthCredential credential, JSObject jsResult) {
    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this.plugin.getContext());
    if (account != null)  {
        jsResult.put("idToken", account.getIdToken());
    } else {
        Log.w(GOOGLE_TAG, "Ops, there was not last signed in account on google api.");
    }
}
 
Example 15
Source File: PlayGamesPlugin.java    From play_games with MIT License 6 votes vote down vote up
private GoogleSignInAccount getLastSignedInAccount() {
    return GoogleSignIn.getLastSignedInAccount(registrar.activity());
}
 
Example 16
Source File: GoogleAccountsProvider.java    From science-journal with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isSignedIn() {
  GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(context);
  return account != null;
}
 
Example 17
Source File: ShortyzActivity.java    From shortyz with GNU General Public License v3.0 6 votes vote down vote up
protected boolean isSignedIn() {
	return GoogleSignIn.getLastSignedInAccount(this) != null;
}
 
Example 18
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 6 votes vote down vote up
private boolean isSignedIn() {
  return GoogleSignIn.getLastSignedInAccount(this) != null;
}
 
Example 19
Source File: GoogleSignInActivity.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
private void checkAlreadySignedIn() {
    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
    updateUi(account);
}
 
Example 20
Source File: GoogleAccountsProvider.java    From science-journal with Apache License 2.0 6 votes vote down vote up
@Override
public int getAccountCount() {
  GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(context);
  return account == null ? 0 : 1;
}