Example usage for android.accounts AccountManager KEY_ACCOUNT_NAME

List of usage examples for android.accounts AccountManager KEY_ACCOUNT_NAME

Introduction

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

Prototype

String KEY_ACCOUNT_NAME

To view the source code for android.accounts AccountManager KEY_ACCOUNT_NAME.

Click Source Link

Document

Bundle key used for the String account name in results from methods which return information about a particular account.

Usage

From source file:com.google.cloud.backend.core.CloudBackendActivity.java

/**
 * Handles callback from Intents like authorization request or account
 * picking./*from   w w  w  .  j  a v  a 2 s .  c om*/
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    case REQUEST_ACCOUNT_PICKER:
        if (data != null && data.getExtras() != null) {

            // set the picked account name to the credential
            String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            credential.setSelectedAccountName(accountName);

            // save account name to shared pref
            SharedPreferences.Editor e = cloudBackend.getSharedPreferences().edit();
            e.putString(PREF_KEY_ACCOUNT_NAME, accountName);
            e.commit();
        }

        // post create initialization
        _onPostCreate();
        break;
    }
}

From source file:io.v.android.apps.syncslides.SignInActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CODE_PICK_ACCOUNT: {
        if (resultCode != RESULT_OK) {
            Toast.makeText(this, "Must pick account", Toast.LENGTH_LONG).show();
            pickAccount();/*from  w ww. j av  a 2s .  co m*/
            break;
        }
        pickAccountDone(data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME));
        break;
    }
    case REQUEST_CODE_FETCH_USER_PROFILE_APPROVAL:
        if (resultCode != RESULT_OK) {
            Log.e(TAG, "User didn't approve oauth2 request");
            break;
        }
        fetchUserProfile();
        break;
    }
}

From source file:dev.drsoran.moloko.auth.AuthenticatorActivity.java

/**
 * Response is received from the server for authentication request. Sets the AccountAuthenticatorResult which is sent
 * back to the caller. Also sets the authToken in AccountManager for this account.
 *//* w w w  .  ja  v a  2  s .  com*/
@Override
public void onAuthenticationFinished(RtmAuth rtmAuth) {
    final Account account = new Account(rtmAuth.getUser().getUsername(), Constants.ACCOUNT_TYPE);
    try {
        boolean ok = true;

        if (isNewAccount) {
            ok = accountManager.addAccountExplicitly(account, rtmAuth.getToken(), null);
            if (ok) {
                ContentResolver.setSyncAutomatically(account, Rtm.AUTHORITY, true);
            }
        }

        if (ok) {
            accountManager.setUserData(account, Constants.FEAT_API_KEY, MolokoApp.getRtmApiKey(this));
            accountManager.setUserData(account, Constants.FEAT_SHARED_SECRET,
                    MolokoApp.getRtmSharedSecret(this));
            accountManager.setUserData(account, Constants.FEAT_PERMISSION, rtmAuth.getPerms().toString());
            accountManager.setUserData(account, Constants.ACCOUNT_USER_ID, rtmAuth.getUser().getId());
            accountManager.setUserData(account, Constants.ACCOUNT_FULLNAME, rtmAuth.getUser().getFullname());

            final Intent intent = new Intent();

            intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, rtmAuth.getUser().getUsername());
            // We store the authToken as password
            intent.putExtra(AccountManager.KEY_PASSWORD, rtmAuth.getToken());
            intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE);
            intent.putExtra(AccountManager.KEY_AUTHTOKEN, rtmAuth.getToken());

            intent.putExtra(AccountManager.KEY_BOOLEAN_RESULT, true);

            setAccountAuthenticatorResult(intent.getExtras());
            setResult(RESULT_OK, intent);
        }
    } catch (SecurityException e) {
        MolokoApp.Log.e(getClass(), e.getLocalizedMessage());
        onAuthenticationFailed(getString(R.string.auth_err_cause_scurity));
    } finally {
        finish();
    }
}

From source file:org.chromium.ChromeIdentity.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
    // Enter only if we have requests waiting
    if (savedContent) {
        if (requestCode == ACCOUNT_CHOOSER_INTENT) {
            if (resultCode == Activity.RESULT_OK && intent.hasExtra(AccountManager.KEY_ACCOUNT_NAME)) {
                accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
                getAuthToken(this.savedCordovaArgs, this.savedCallbackContext);
            } else {
                this.savedCallbackContext.error("User declined to provide an account");
            }/* w  w w  .  j  a  v  a  2  s .c  o m*/
            this.savedContent = false;
            this.savedCallbackContext = null;
            this.savedCordovaArgs = null;
        } else if (requestCode == OAUTH_PERMISSIONS_GRANT_INTENT) {
            cordova.getThreadPool().execute(new Runnable() {
                @Override
                public void run() {
                    if (resultCode == Activity.RESULT_OK) {
                        String token = null;
                        if (intent.hasExtra("authtoken")) {
                            token = intent.getStringExtra("authtoken");
                        } else {
                            try {
                                token = GoogleAuthUtil.getToken(cordova.getActivity(),
                                        intent.getExtras().getString("authAccount"),
                                        intent.getExtras().getString("service"));
                            } catch (UserRecoverableAuthException e) {
                                e.printStackTrace();
                                savedCallbackContext.error("Auth Error: " + e.getMessage());
                                return;
                            } catch (IOException e) {
                                e.printStackTrace();
                                savedCallbackContext.error("Auth Error: " + e.getMessage());
                                return;
                            } catch (GoogleAuthException e) {
                                e.printStackTrace();
                                savedCallbackContext.error("Auth Error: " + e.getMessage());
                                return;
                            }
                        }
                        if (token == null) {
                            savedCallbackContext.error("Unknown auth error.");
                        } else {
                            getAuthTokenCallback(token, savedCallbackContext);
                        }
                    } else {
                        savedCallbackContext.error("User did not approve oAuth permissions request");
                    }
                    savedContent = false;
                    savedCallbackContext = null;
                    savedCordovaArgs = null;
                }
            });
        } else if (requestCode == UPDATE_GOOGLE_PLAY_SERVICES_REQUEST_CODE) {
            if (resultCode == Activity.RESULT_OK) {
                // The user has updated Google Play Services.  Try again!
                launchAccountChooserAndCallback(savedCordovaArgs, savedCallbackContext);
            } else {
                // Google Play Services was not updated.
                savedCallbackContext.error("Google Play Services is out of date.");

                savedContent = false;
                savedCallbackContext = null;
                savedCordovaArgs = null;
            }
        }
    }
}

From source file:com.pindroid.activity.FragmentBaseActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_CANCELED && requestCode != Constants.REQUEST_CODE_ACCOUNT_CHANGE) {
        finish();/*  w ww  . j  a va 2  s .co  m*/
    } else if (resultCode == Activity.RESULT_OK && requestCode == Constants.REQUEST_CODE_ACCOUNT_CHANGE) {
        setAccount(data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME));
    } else if (resultCode == Activity.RESULT_OK && requestCode == Constants.REQUEST_CODE_ACCOUNT_INIT) {
        setAccount(AccountHelper.getFirstAccount(this).name);
    }
}

From source file:me.philio.ghost.ui.LoginActivity.java

@Override
public void onSuccess(String email, String password, Token token, User user) {
    // Create the account
    Account account = new Account(AccountUtils.getName(mBlogUrl, email), getString(R.string.account_type));
    Bundle userdata = new Bundle();
    userdata.putString(KEY_BLOG_URL, mBlogUrl);
    userdata.putString(KEY_EMAIL, email);
    userdata.putString(KEY_ACCESS_TOKEN_TYPE, token.tokenType);
    userdata.putString(KEY_ACCESS_TOKEN_EXPIRES,
            Long.toString(System.currentTimeMillis() + (token.expires * 1000)));

    // Add account to the system
    AccountManager accountManager = AccountManager.get(this);
    accountManager.addAccountExplicitly(account, password, userdata);

    // Set the account auth tokens
    accountManager.setAuthToken(account, TOKEN_TYPE_ACCESS, token.accessToken);
    accountManager.setAuthToken(account, TOKEN_TYPE_REFRESH, token.refreshToken);

    // Create initial database records
    Blog blog = new Blog();
    blog.url = mBlogUrl;//from   w w  w  .  j av  a 2  s .c o  m
    blog.email = email;
    user.blog = blog;
    ActiveAndroid.beginTransaction();
    try {
        blog.save();
        user.save();
        ActiveAndroid.setTransactionSuccessful();
    } finally {
        ActiveAndroid.endTransaction();
    }

    // Enable sync for the account
    ContentResolver.setSyncAutomatically(account, getString(R.string.content_authority), true);
    SyncHelper.requestSync(account, getString(R.string.content_authority));

    // Set response intent
    Intent intent = new Intent();
    intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, account.name);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, account.type);
    setAccountAuthenticatorResult(intent.getExtras());
    setResult(RESULT_OK, intent);
    finish();
}

From source file:com.activiti.android.app.fragments.integration.alfresco.AlfrescoIntegrationFragment.java

public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (requestCode == 10 && resultCode == Activity.RESULT_OK) {
        String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
        Account[] accounts = AccountManager.get(getActivity())
                .getAccountsByType(AlfrescoIntegrator.ALFRESCO_ACCOUNT_TYPE);
        for (int i = 0; i < accounts.length; i++) {
            if (accountName.equals(accounts[i].name)) {
                selectedAccount = accounts[i];
                break;
            }//from  w  w  w .  ja v a2  s.c om
        }
    }
}

From source file:com.smashedin.facebook.HelloFacebookSampleActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback);
    if (requestCode == REQUEST_CODE_PICK_ACCOUNT) {
        if (resultCode == RESULT_OK) {
            mEmail = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            getUsername();/*ww w  .ja va  2 s.  com*/
        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(this, "You must pick an account", Toast.LENGTH_SHORT).show();
        }
    } else if ((requestCode == REQUEST_CODE_RECOVER_FROM_AUTH_ERROR
            || requestCode == REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR) && resultCode == RESULT_OK) {
        handleAuthorizeResult(resultCode, data);
        return;
    }
}

From source file:com.google.cloud.backend.neednow.core.CloudBackendFragment.java

/**
 * Handles callback from Intents like authorization request or account
 * picking. If the hosting Activity also makes use of onActivityResult, make
 * sure the Activity calls super.onActivityResult to handle all
 * requestCodes, including the code here. Forgetting to call the super
 * method is a common mistake and is often cause for confusion.
 *//*  www  .j  av a 2  s .c  om*/
@Override
public final void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    Log.i("result from activity", "resultcode: " + resultCode);
    switch (requestCode) {
    case REQUEST_ACCOUNT_PICKER:
        if (data != null && data.getExtras() != null) {

            // set the picked account name to the credential
            String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            mCredential.setSelectedAccountName(accountName);

            // save account name to shared pref
            SharedPreferences.Editor e = mCloudBackend.getSharedPreferences().edit();
            e.putString(Consts.PREF_KEY_ACCOUNT_NAME, accountName);
            e.commit();
        } else
            Log.i("result unavailable", "resultcode: " + resultCode);

        // post create initialization

        break;

    default:
        Log.i("case not matching", "resultcode: " + resultCode);
        break;
    }
}

From source file:io.v.android.impl.google.services.blessing.BlessingActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CODE_PICK_ACCOUNT:
        if (resultCode != RESULT_OK) {
            replyWithError("User didn't pick account.");
            return;
        }//from ww  w. j av  a 2 s.c  o  m
        mGoogleAccount = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
        if (mGoogleAccount == null || mGoogleAccount.isEmpty()) {
            replyWithError("Empty Google email.");
            return;
        }
        getBlessing();
        break;
    case REQUEST_CODE_USER_APPROVAL:
        if (resultCode != RESULT_OK) {
            replyWithError("User didn't give proposed permissions.");
            return;
        }
        getBlessing();
        break;
    default:
        super.onActivityResult(requestCode, resultCode, data);
    }
}