Example usage for android.accounts AccountManager confirmCredentials

List of usage examples for android.accounts AccountManager confirmCredentials

Introduction

In this page you can find the example usage for android.accounts AccountManager confirmCredentials.

Prototype

public AccountManagerFuture<Bundle> confirmCredentials(final Account account, final Bundle options,
        final Activity activity, final AccountManagerCallback<Bundle> callback, final Handler handler) 

Source Link

Document

Confirms that the user knows the password for an account to make extra sure they are the owner of the account.

Usage

From source file:net.heroicefforts.viable.android.rep.it.GIssueTrackerRepository.java

private void manageAccount() {
    AccountManager accMgr = (AccountManager) act.getSystemService(Context.ACCOUNT_SERVICE);
    if (Config.LOGD)
        Log.d(TAG, "Requesting account creation.");
    Account[] accts = accMgr.getAccountsByType(GCLAccountAuthenticator.ACCT_TYPE);
    if (accts.length > 0)
        accMgr.confirmCredentials(accts[0], null, act, callback, null);
    else/*from   ww w .  j av  a 2 s  .c  om*/
        accMgr.addAccount(GCLAccountAuthenticator.ACCT_TYPE, GCLAccountAuthenticator.TOKEN_TYPE_ISSUE_TRACKER,
                null, null, act, callback, null);
}

From source file:com.sefford.beauthentic.activities.LoginActivity.java

void createGoogleAccount(final GoogleSignInAccount acct) {
    final Account account = new Account(acct.getDisplayName(), AuthenticAuthenticator.ACCOUNT_TYPE);
    final AccountManager am = AccountManager.get(this);
    final Bundle data = new Bundle();
    data.putInt(AuthenticAuthenticator.EXTRA_TYPE, AuthenticAuthenticator.Type.GOOGLE.ordinal());
    data.putString(AccountManager.KEY_ACCOUNT_NAME, acct.getDisplayName());
    data.putString(AccountManager.KEY_AUTHTOKEN, acct.getIdToken());
    am.confirmCredentials(account, data, null, new AccountManagerCallback<Bundle>() {
        @Override//from ww w .j a v  a  2s.  com
        public void run(AccountManagerFuture<Bundle> future) {
            try {
                final Bundle result = future.getResult();
                if (result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT)) {
                    Sessions.addAccount(am, account, "", Bundle.EMPTY);
                    am.setAuthToken(account, AuthenticAuthenticator.AUTHTOKEN_TYPE,
                            result.getString(AccountManager.KEY_AUTHTOKEN));
                    am.setUserData(account, AuthenticAuthenticator.EXTRA_TYPE,
                            Integer.toString(AuthenticAuthenticator.Type.GOOGLE.ordinal()));
                    notifyLoginToGCM(AuthenticAuthenticator.Type.GOOGLE.ordinal(), account.name, "",
                            result.getString(AccountManager.KEY_AUTHTOKEN));
                    googleApi.saveCredential(new Credential.Builder(acct.getEmail())
                            .setAccountType(IdentityProviders.GOOGLE).setName(acct.getDisplayName())
                            .setProfilePictureUri(acct.getPhotoUrl()).build(),
                            new SmartlockCredentialCallback());
                }
            } catch (OperationCanceledException e) {
                Snackbar.make(vLoginForm, R.string.error_operation_cancelled, Snackbar.LENGTH_LONG).show();
            } catch (IOException e) {
                Snackbar.make(vLoginForm, R.string.error_not_connected_to_internet, Snackbar.LENGTH_LONG)
                        .show();
            } catch (AuthenticatorException e) {
                Snackbar.make(vLoginForm, R.string.error_invalid_credentials, Snackbar.LENGTH_LONG).show();
            }
        }
    }, null);
}