Java Code Examples for com.google.android.gms.common.AccountPicker#newChooseAccountIntent()

The following examples show how to use com.google.android.gms.common.AccountPicker#newChooseAccountIntent() . 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: GoogleOauth2.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
private void pickUserAccount() {
    try {
        String[] accountTypes = new String[]{"com.google"};
        Intent intent = AccountPicker.newChooseAccountIntent(null, null,
                accountTypes, true, null, null, null, null);
        if ( activity == null )
            return;
        // check if play-services are installed
        int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
        if (ConnectionResult.SUCCESS == result) {
            activity.startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT);
            logger.debug("Launching google account picker ...");
        } else {
            // display user friendly error message
            logger.debug("Play services are missing ...");
            GooglePlayServicesUtil.getErrorDialog(result, activity, 100).show();
        }
    } catch (ActivityNotFoundException ex) {
        logger.debug("Google-play-services are missing? cannot login by google");
    }
}
 
Example 2
Source File: MainActivity.java    From conference-central-android-app with GNU General Public License v2.0 6 votes vote down vote up
private void selectAccount() {
    Account[] accounts = Utils.getGoogleAccounts(this);
    int numOfAccount = accounts.length;
    switch (numOfAccount) {
        case 0:
            // No accounts registered, nothing to do.
            Toast.makeText(this, R.string.toast_no_google_accounts_registered,
                    Toast.LENGTH_LONG).show();
            break;
        case 1:
            mEmailAccount = accounts[0].name;
            performAuthCheck(mEmailAccount);
            break;
        default:
            // More than one Google Account is present, a chooser is necessary.
            // Invoke an {@code Intent} to allow the user to select a Google account.
            Intent accountSelector = AccountPicker.newChooseAccountIntent(null, null,
                    new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, false,
                    getString(R.string.select_account_for_access), null, null, null);
            startActivityForResult(accountSelector, ACTIVITY_RESULT_FROM_ACCOUNT_SELECTION);
    }
}
 
Example 3
Source File: EmailPlugin.java    From capacitor-email with MIT License 5 votes vote down vote up
@PluginMethod()
public void requestPermission(PluginCall call) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        Intent intent = AccountPicker.newChooseAccountIntent(null, null,
                null, false, null, null, null, null);
        startActivityForResult(call, intent, REQUEST_CODE);
    } else {
        requestAccountPermission();
    }
}
 
Example 4
Source File: PreferencesActivity.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
private void chooseAccount() {
    try {
        if (isRequestingPermissions(this, GET_ACCOUNTS, "android.permission.USE_CREDENTIALS")) {
            return;
        }
        Account selectedAccount = getSelectedAccount();
        Intent intent = AccountPicker.newChooseAccountIntent(selectedAccount, null,
                new String[]{"com.google"}, true, null, null, null, null);
        startActivityForResult(intent, CHOOSE_ACCOUNT);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, R.string.google_drive_account_select_error, Toast.LENGTH_LONG).show();
    }
}
 
Example 5
Source File: GoogleAccountCredential.java    From google-api-java-client with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an intent to show the user to select a Google account, or create a new one if there are
 * none on the device yet.
 *
 * <p>
 * Must be run from the main UI thread.
 * </p>
 */
public final Intent newChooseAccountIntent() {
  return AccountPicker.newChooseAccountIntent(selectedAccount,
      null,
      new String[] {GoogleAccountManager.ACCOUNT_TYPE},
      true,
      null,
      null,
      null,
      null);
}
 
Example 6
Source File: MainActivity.java    From gplus-haiku-client-android with Apache License 2.0 5 votes vote down vote up
/**
 * Begin the non-immediate sign in flow
 */
private void beginSignInFlow() {
    setProgressBarIndeterminateVisibility(true);
    HaikuSession.State state = mHaikuPlusSession.checkSessionState(true);
    mSignInClicked = true;

    if (state == HaikuSession.State.UNAUTHENTICATED) {
        Intent intent = AccountPicker.newChooseAccountIntent(
                null, null, new String[]{"com.google"},
                false, null, null, null, null);
        startActivityForResult(intent, REQ_CHOOSE_ACCOUNT);
    } else {
        mGoogleApiClient.connect();
    }
}
 
Example 7
Source File: TGDriveBrowserSettingsFactory.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void createSettings() {
	Intent chooseAccountIntent = AccountPicker.newChooseAccountIntent(null, null, new String[] {GoogleAccountManager.ACCOUNT_TYPE}, true, null, null, null, null);
	
	this.activity.getResultManager().addHandler(this.requestCode, this);
	this.activity.startActivityForResult(chooseAccountIntent, this.requestCode);
}
 
Example 8
Source File: MainActivity.java    From SyncManagerAndroid-DemoGoogleTasks with MIT License 4 votes vote down vote up
protected void pickUserAccount() {
    String[] accountTypes = new String[]{"com.google"};
    Intent intent = AccountPicker.newChooseAccountIntent(null, null,
            accountTypes, false, null, null, null, null);
    startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT);
}