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"); } }
@Override public void onResume() { super.onResume(); if (!SettingsUtil.isAccountSelected(getActivity())) { final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity().getApplicationContext()); if (status == ConnectionResult.SUCCESS) { startActivityForResult( AccountPicker.newChooseAccountIntent(null, null, new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }, false, null, null, null, null), UserSettingsActivity.REQUEST_CODE_ACCOUNT_NAME); } else { GooglePlayServicesUtil.getErrorDialog(status, getActivity(), UserSettingsActivity.REQUEST_CODE_PLAY_SERVICES_NOT_AVAILABLE).show(); } } initLoader(); getLoaderManager().restartLoader(ILoader.COURSES_LOADER_ID, null, this); }
@Override public void onResume() { super.onResume(); if (!SettingsUtil.isAccountSelected(getActivity())) { final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity().getApplicationContext()); if (status == ConnectionResult.SUCCESS) { startActivityForResult( AccountPicker.newChooseAccountIntent(null, null, new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }, false, null, null, null, null), UserSettingsActivity.REQUEST_CODE_ACCOUNT_NAME); } else { GooglePlayServicesUtil.getErrorDialog(status, getActivity(), UserSettingsActivity.REQUEST_CODE_PLAY_SERVICES_NOT_AVAILABLE).show(); } } getLoaderManager().restartLoader(ILoader.STUDENTS_LOADER_ID, null, this); }
@Override public boolean onPreferenceClick(Preference preference) { if (preference.getKey().equals(getString(R.string.btnSelectGoogleAccount_key))) { final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity().getApplicationContext()); if (status == ConnectionResult.SUCCESS) { startActivityForResult(AccountPicker.newChooseAccountIntent(SettingsUtil.getSelectedGoogleAccount(getActivity()), null, new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }, false, null, null, null, null), UserSettingsActivity.REQUEST_CODE_ACCOUNT_NAME); return true; } else { GooglePlayServicesUtil.getErrorDialog(status, getActivity(), UserSettingsActivity.REQUEST_CODE_PLAY_SERVICES_NOT_AVAILABLE).show(); } } return true; }
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); } }
@Kroll.method public void signin(KrollDict props) { if (props.containsKey("success")) { successCallback = (KrollFunction) props.get("success"); } if (props.containsKey("error")) { errorCallback = (KrollFunction) props.get("error"); } String[] accountTypes = new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }; Intent intent = AccountPicker.newChooseAccountIntent(null, null, accountTypes, false, null, null, null, null); Activity activity = TiApplication.getAppCurrentActivity(); TiActivitySupport support = (TiActivitySupport) activity; requestCode = support.getUniqueResultCode(); support.launchActivityForResult(intent, requestCode, this); }
/** * Enforce an active Google Account by checking to see if an active account is already set. If * it is not set then use the {@link AccountPicker} to have the user select an account. * * @param activity The context to be used for starting an activity. * @param activityResultCode The result to be used to start the {@link AccountPicker}. * @return Returns whether the user already has an active account registered. */ public static boolean enforceActiveGoogleAccount(Activity activity, int activityResultCode) { if (hasActiveAccount(activity)) { return true; } else { Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, true, null, null, null, null); activity.startActivityForResult(intent, activityResultCode); return false; } }
private void chooseAccount() { try { Account selectedAccount = getSelectedAccount(); Intent intent = AccountPicker.newChooseAccountIntent(selectedAccount, null, ACCOUNT_TYPE, 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(); } }
/** * Pick up a Google account from the device. See http://developer.android.com/google/auth/http-auth.html. */ public void chooseAccount() { String[] accountTypes = new String[]{"com.google"}; Intent intent = AccountPicker.newChooseAccountIntent(null, null, accountTypes, false, null, null, null, null); startActivityForResult(intent, IntentRequestCode.REQUEST_ACCOUNT_PICKER); }
private void pickUserAccount() { String[] accountTypes = new String[]{"com.google"}; Intent mIntent = AccountPicker.newChooseAccountIntent(null, null, accountTypes, false, null, null, null, null); if (mIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(mIntent, REQUEST_CODE_PICK_ACCOUNT); } }
private void chooseFlowzrAccount() { try { Account selectedAccount = getFlowzrSelectedAccount(); Intent intent = AccountPicker.newChooseAccountIntent(selectedAccount, null, ACCOUNT_TYPE, 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(); } }
private void askUserEmail() { try { Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, false, null, null, null, null); startActivityForResult(intent, REQUEST_CODE_EMAIL); } catch (ActivityNotFoundException e) { Log.e(TAG, e.getMessage()); } }
private void askUserEmail() { try { Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, false, null, null, null, null); startActivityForResult(intent, SettingsFragment.REQUEST_CODE_EMAIL); } catch (ActivityNotFoundException e) { } }
/** * onActivityResult will be called either in the Activity/Fragment depending on whether a Fragment is attached. */ public void pickAccount() { String[] accountTypes = new String[]{ACCOUNT_TYPE_GOOGLE}; Intent intent = AccountPicker.newChooseAccountIntent(null, null, accountTypes, false, null, null, null, null); if (mFragment != null) { mFragment.startActivityForResult(intent, REQUEST_ACCOUNT_PICKER); } else { mActivity.startActivityForResult(intent, REQUEST_ACCOUNT_PICKER); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Shows Account Picker with google accounts if not stored in shared // preferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); Boolean accountFound = false; if (sharedPrefs.contains("gmailId")) { Account[] accounts = AccountManager.get(this) .getAccounts(); accountName = sharedPrefs.getString("gmailId", null); for (Account a : accounts) { if (a.type.equals(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE) && a.name.equals(accountName)) { accountFound = true; new getAuthToken().execute(); break; } } } if (!accountFound) { Intent googlePicker = AccountPicker.newChooseAccountIntent(null, null, new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, true, null, null, null, null); startActivityForResult(googlePicker, 1); } }
private void pickUserAccount (CallbackContext callbackContext) { tryConnectCallback = callbackContext; String[] accountTypes = new String[]{"com.google"}; Intent intent = AccountPicker.newChooseAccountIntent (null, null, accountTypes, false, null, null, null, null); doSetResultCallBack (); cordova.getActivity().startActivityForResult (intent, REQUEST_CODE_PICK_ACCOUNT); }
/** * Method to request the user choose an account. */ private boolean triggerAccountSelection() { if (!checkGooglePlayServicesAvailable()) { return false; } Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[]{"com.google"}, false, getString(R.string.auth_description), null, null, null); startActivityForResult(intent, REQ_CHOOSE_ACCOUNT); return true; }
/** * Show the dialog for user to select one Google Account */ private 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); }
/** Starts an activity in Google Play Services so the user can pick an account */ private 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); }
/** * pick a user account with the request id {@link com.rockyniu.todolist.util.Constance.REQUEST_USER_PICKER} */ private void onUserPicker(Activity activity) { Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }, true, null, null, null, null); try { activity.startActivityForResult(intent, Constance.REQUEST_USER_PICKER); } catch (Exception e) { ToastHelper.showErrorToast(activity, activity.getResources().getString(R.string.fail_to_add_new_user)); } }
/** * @param activity {@link Activity} used to start the account picker activity. * @param account The currently selected {@link Account}. * @param requestCode If >= 0, this code will be returned in onActivityResult() when the activity exits. * @param accountType The type of accounts to choose from. */ public static void startAccountPicker(final Activity activity, final Account account, final int requestCode, final Bundle options, final String... accountType) { final Intent intent = AccountPicker.newChooseAccountIntent(account, null, accountType, true, null, null, null, options); activity.startActivityForResult(intent, requestCode); }
private void launchAccountChooserAndCallback(CordovaArgs cordovaArgsToSave, CallbackContext callbackContextToSave) { // Check if Google Play Services is available. int availabilityCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this.cordova.getActivity()); if (availabilityCode == ConnectionResult.SUCCESS) { this.savedCordovaArgs = cordovaArgsToSave; this.savedCallbackContext = callbackContextToSave; this.savedContent = true; // The "google.com" filter accepts both Google and Gmail accounts. Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[]{"com.google"}, false, null, null, null, null); this.cordova.startActivityForResult(this, intent, ACCOUNT_CHOOSER_INTENT); } else { callbackContextToSave.error(GOOGLE_PLAY_SERVICES_UNAVAILABLE); } }
/** * This method is invoked when the "Sign In" button is clicked. See activity_main.xml for the * dynamic reference to this method. */ public void onClickSignIn(View view) { TextView emailAddressTV = (TextView) view.getRootView().findViewById(id.email_address_tv); // Check to see how many Google accounts are registered with the device. int googleAccounts = AppConstants.countGoogleAccounts(this); if (googleAccounts == 0) { // No accounts registered, nothing to do. Toast.makeText(this, R.string.toast_no_google_accounts_registered, Toast.LENGTH_LONG).show(); } else if (googleAccounts == 1) { // If only one account then select it. Toast.makeText(this, R.string.toast_only_one_google_account_registered, Toast.LENGTH_LONG).show(); AccountManager am = AccountManager.get(this); Account[] accounts = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE); if (accounts != null && accounts.length > 0) { // Select account and perform authorization check. emailAddressTV.setText(accounts[0].name); mEmailAccount = accounts[0].name; performAuthCheck(accounts[0].name); } } else { // More than one Google Account is present, a chooser is necessary. // Reset selected account. emailAddressTV.setText(""); // 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, "Select the account to access Google Compute Engine API.", null, null, null); startActivityForResult(accountSelector, ACTIVITY_RESULT_FROM_ACCOUNT_SELECTION); } }
/** * 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(); } }
private void googlePickUserAccount() { String[] accountTypes = new String[]{"com.google"}; Intent intent = AccountPicker.newChooseAccountIntent(null, null, accountTypes, false, null, null, null, null); startActivityForResult(intent, GOOGLE_REQUEST_CODE_PICK_ACCOUNT); }
/** * Starts an activity in Google Play Services so the user can pick an * account */ private 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); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.google_login); mKinveyClient = ((UserLogin) getApplication()).getKinveyService(); mAccountManager = AccountManager.get(this); Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[] { "com.google" }, false, null, null, null, null); startActivityForResult(intent, GPLAY_REQUEST_CODE); }
@Override public void onClick(View view) { if (view == findViewById(R.id.add_account_button)) { Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }, false, null, null, null, null); try{ startActivityForResult(intent, REQUEST_ACCOUNT_PICKER); } catch (Exception e){ checkGooglePlaySerViceAvailable(MainActivity.this); } } }
@Override public void onClick(View v) { int viewId = v.getId(); switch (viewId) { case R.id.error_button: if (mLastStatus.isError() && mLastStatus.isCustomIssue()) { String error = mLastStatus.getMsgObjectAsStringOrThrow(); if (DownloadService.STATE_TOKEN_INVALID.equals(error)) { new AuthAsyncTask(mActivity, mRefreshUri).execute(); } else if (DownloadService.STATE_REAUTHORIZE.equals(error)) { Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[] { "com.google" }, false, null, null, null, null); mActivity.startActivityForResult(intent, REQUEST_PICK_ACCOUNT); } else if (DownloadService.STATE_UNSUPPORTED_DEVICE .equals(error)) { int connectionResult = GooglePlayServicesUtil .isGooglePlayServicesAvailable(mActivity); checkState(connectionResult != ConnectionResult.SUCCESS); Dialog dialog = GooglePlayServicesUtil.getErrorDialog( connectionResult, mActivity, REQUEST_SHOW_ERROR); dialog.show(); } else { throw new RuntimeException("Unknown error: " + error); } } else { DownloadHelper.startAsyncDownload(mActivity, DownloadService.ACTION_SYNC, mRefreshUri, null, true); } return; default: throw new RuntimeException(); } }
private void pickUserAccount() { String[] accountTypes = new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}; Intent intent = AccountPicker.newChooseAccountIntent(null, null, accountTypes, false, null, null, null, null); startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT); }
public void selectAccount(View view) { //handle click for Google Account edit text Intent googlePicker = AccountPicker.newChooseAccountIntent(null, null, new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, true, null, null, null, null); startActivityForResult(googlePicker, REQUEST_CODE); }
private void pickAccount() { Intent intent = AccountPicker.newChooseAccountIntent( null, null, new String[]{"com.google"}, false, null, null, null, null); startActivityForResult(intent, SIGN_IN_RETURN_CODE); }