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.sharpcart.android.wizardpager.SharpCartLoginActivity.java

private void createAccount(final String mUsername, final String mPassword) {
    final Account account = new Account(mUsername, PARAM_ACCOUNT_TYPE);

    if (mRequestNewAccount) {
        mAccountManager.addAccountExplicitly(account, mPassword, null);

        /*//w w  w  . j  ava 2s  . c  o m
         * Turn on periodic syncing. I need to add randomness to the sync interval to make sure 
         * that not all users sync at the same time, which will overload the server.
         */

        final Bundle extras = new Bundle();
        final long random = (long) (Math.random() * 1000L);

        ContentResolver.addPeriodicSync(account, SharpCartContentProvider.AUTHORITY, extras,
                (8 * SYNC_INTERVAL) + random);

        //Will run the syncadapter everytime we get a network tinkle
        //ContentResolver.setSyncAutomatically(account,SharpCartContentProvider.AUTHORITY, true);

        //initiate a sync
        SharpCartUtilities.getInstance().syncFromServer(account);

    } else {
        mAccountManager.setPassword(account, mPassword);
    }

    final Intent intent = new Intent();
    intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, PARAM_ACCOUNT_TYPE);

    if (mAuthTokenType != null && mAuthTokenType.equals(PARAM_AUTHTOKEN_TYPE)) {
        intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAuthToken);
    }

    setResult(RESULT_OK, intent);

    finish();
}

From source file:it.gmariotti.android.examples.googleaccount.SmsRestoreGDriveActivity.java

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    switch (requestCode) {
    case REQUEST_ACCOUNT_PICKER:

        if (resultCode == RESULT_OK) {
            mAccountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
            prefs.edit().putString(PREF_ACCOUNT_NAME, mAccountName).commit();

            if (mAccountName != null) {
                restoreSmsFromGDrive();/*from  w w w .  j  av  a 2  s  .c  o  m*/
            }

        }
        break;
    case REQUEST_AUTHORIZATION_FOLDER:
        if (resultCode == RESULT_OK) {
            restoreSmsFromGDrive();
        } else {
            startActivityForResult(mCredential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
        }
        break;

    }
}

From source file:org.ohmage.authenticator.AuthenticatorActivity.java

/**
 * Called when response is received from the server for authentication
 * request. See onAuthenticationResult(). Sets the
 * AccountAuthenticatorResult which is sent back to the caller. Also sets
 * the authToken in AccountManager for this account.
 * /*from  w w  w. ja v a2  s  .  c  o  m*/
 * @param the confirmCredentials result.
 */

protected void createAccount() {
    Log.v(TAG, "finishLogin()");
    final Account account = new Account(mUsername, OhmageApplication.ACCOUNT_TYPE);
    Bundle userData = new Bundle();
    userData.putString(KEY_OHMAGE_SERVER, ConfigHelper.serverUrl());
    mAuthtoken = mHashedPassword;

    if (TextUtils.isEmpty(mAuthtoken)) {
        Log.w(TAG, "Trying to create account with empty password");
        return;
    }

    if (mRequestNewAccount) {
        mAccountManager.addAccountExplicitly(account, mPassword, userData);
        mAccountManager.setAuthToken(account, OhmageApplication.AUTHTOKEN_TYPE, mAuthtoken);
        // Set sync for this account.
        ContentResolver.setIsSyncable(account, DbContract.CONTENT_AUTHORITY, 1);
        ContentResolver.setSyncAutomatically(account, DbContract.CONTENT_AUTHORITY, true);
        ContentResolver.addPeriodicSync(account, DbContract.CONTENT_AUTHORITY, new Bundle(), 3600);
    } else {
        mAccountManager.setPassword(account, mPassword);
    }
    final Intent intent = new Intent();
    intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, OhmageApplication.ACCOUNT_TYPE);
    if (mAuthtokenType != null && mAuthtokenType.equals(OhmageApplication.AUTHTOKEN_TYPE)) {
        intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAuthtoken);
    }
    setAccountAuthenticatorResult(intent.getExtras());
    setResult(RESULT_OK, intent);

    mPreferencesHelper.edit().putLoginTimestamp(System.currentTimeMillis()).commit();

    if (UserPreferencesHelper.isSingleCampaignMode()) {
        // Download the single campaign
        showDialog(DIALOG_DOWNLOADING_CAMPAIGNS);
        getSupportLoaderManager().restartLoader(0, null, this);
    } else {
        finishLogin();
    }
}

From source file:com.einzig.ipst2.activities.MainActivity.java

private void onLoginResult(int resultCode, Intent data) {
    PreferencesHelper helper = new PreferencesHelper(getApplicationContext());
    if (resultCode != RESULT_OK) {
        runOnUiThread(new Runnable() {
            @Override//from  w  w w  .  ja  v a  2  s  .c  o m
            public void run() {
                findViewById(R.id.progress_view_mainactivity).setVisibility(View.INVISIBLE);
                findViewById(R.id.gmail_login_button).setVisibility(View.VISIBLE);
            }
        });
        return;
    }
    helper.set(helper.emailKey(), data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME));
    Account me = getAccount();
    if (me != null) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    } else {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                findViewById(R.id.progress_view_mainactivity).setVisibility(View.INVISIBLE);
                findViewById(R.id.gmail_login_button).setVisibility(View.VISIBLE);
            }
        });
        errorFoundMessage(R.string.accountnotfoundtitle, R.string.accountnotfoundmessage);
    }
    Logger.d("Got account name " + data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME));
    parseEmail();
}

From source file:com.amrutpatil.makeanote.NotesActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case AppConstant.REQ_ACCPICK: {
        //If we picked a valid email account
        if (resultCode == Activity.RESULT_OK && data != null) {
            String email = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            if (GDUT.AM.setEmil(email) == GDUT.AM.CHANGED) {
                GDActions.init(this, GDUT.AM.getActiveEmil());
                GDActions.connect(true);
            }//from  www  . ja v  a 2s .c  o  m
        } else if (GDUT.AM.getActiveEmil() == null) { // if we do not have a valid email from the account picker
            GDUT.AM.removeActiveAccnt();
            finish();
        }
        break;
    }

    case AppConstant.REQ_AUTH:

    case AppConstant.REQ_RECOVER: {
        mIsInAuth = false;
        if (resultCode == Activity.RESULT_OK) {
            GDActions.connect(true);
        } else if (resultCode == RESULT_CANCELED) {
            GDUT.AM.removeActiveAccnt();
            finish();
        }
    }
        break;
    }
}

From source file:com.aimfire.main.MainActivity.java

/**
 * Override Activity lifecycle method.//  w  ww .ja  v  a 2s .  c om
 * handles media player and intro activity results
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // handle request codes
    ActivityCode code = ActivityCode.values()[requestCode];

    switch (code) {
    case INTRO:
        mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.TUTORIAL_COMPLETE, null);
        showHint();
        break;
    case CAMCORDER:
        if (resultCode == Activity.RESULT_CANCELED) {
            /*
             * if user didn't attempt to connect
             */
            showInvite();
        } else {
            /*
             * remember if this device ever attempted to pair with another device
             */
            updateDualModePref();
        }
        break;
    case ACCOUNT_PICKER:
        if (data != null && data.getExtras() != null) {
            // set the picked account name to the credential
            String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            mAimfireService.getCredential().setSelectedAccountName(accountName);

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

        // post create initialization
        mAimfireService.setAccount();
        break;
    default:
        break;
    }

    // call super method to ensure unhandled result codes are handled
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:org.ohmage.auth.AuthenticatorActivity.java

private void finishAccountAdd(String accountName, String authToken, String password) {
    final Intent intent = new Intent();
    intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, accountName);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AuthUtil.ACCOUNT_TYPE);
    if (authToken != null)
        intent.putExtra(AccountManager.KEY_AUTHTOKEN, authToken);
    intent.putExtra(AccountManager.KEY_PASSWORD, password);
    setAccountAuthenticatorResult(intent.getExtras());
    setResult(RESULT_OK, intent);/* ww w.j av a  2  s  .com*/
    finish();

    if (!calledByAuthenticator())
        startActivity(new Intent(getBaseContext(), MainActivity.class));
}

From source file:org.odk.collect.android.activities.GoogleDriveActivity.java

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    switch (requestCode) {
    case REQUEST_ACCOUNT_PICKER:
        if (resultCode == RESULT_OK && data != null && data.getExtras() != null) {
            String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            if (accountName != null) {
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
                SharedPreferences.Editor editor = prefs.edit();
                editor.putString(PreferenceKeys.KEY_SELECTED_GOOGLE_ACCOUNT, accountName);
                editor.apply();/* w  w w. ja v  a2  s.c  o  m*/
                credential.setSelectedAccountName(accountName);
                getResultsFromApi();
            }
        }
        break;
    case REQUEST_AUTHORIZATION:
        if (resultCode == RESULT_OK) {
            getResultsFromApi();
        }
        break;

    case COMPLETE_AUTHORIZATION_REQUEST_CODE:
        if (resultCode == Activity.RESULT_OK) {
            if (isDeviceOnline()) {
                listFiles(ROOT_KEY);
            } else {
                createAlertDialog(getString(R.string.no_connection));
            }
        } else {
            // User denied access, show him the account chooser again
        }
        break;
    }
    if (resultCode == RESULT_CANCELED) {
        finish();
    }

}

From source file:cw.kop.autobackground.sources.SourceInfoFragment.java

@Override
public void onActivityResult(int requestCode, int responseCode, Intent intent) {

    if (requestCode == GoogleAccount.GOOGLE_ACCOUNT_SIGN_IN) {
        if (intent != null && responseCode == Activity.RESULT_OK) {
            final String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            AppSettings.setGoogleAccountName(accountName);
            new AsyncTask<Void, Void, Void>() {
                @Override/* w w  w  .j  ava  2  s .c  o  m*/
                protected Void doInBackground(Void... params) {
                    try {
                        String authToken = GoogleAuthUtil.getToken(appContext, accountName,
                                "oauth2:https://picasaweb.google.com/data/");
                        AppSettings.setGoogleAccountToken(authToken);
                        AppSettings.setGoogleAccount(true);
                        new PicasaAlbumTask(-1, true).execute();
                    } catch (IOException transientEx) {
                        return null;
                    } catch (UserRecoverableAuthException e) {
                        e.printStackTrace();
                        startActivityForResult(e.getIntent(), GoogleAccount.GOOGLE_AUTH_CODE);
                        return null;
                    } catch (GoogleAuthException authEx) {
                        return null;
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    return null;
                }
            }.execute();
        }
    }
    if (requestCode == GoogleAccount.GOOGLE_AUTH_CODE) {
        if (responseCode == Activity.RESULT_OK) {
            new AsyncTask<Void, Void, Void>() {
                @Override
                protected Void doInBackground(Void... params) {
                    try {
                        String authToken = GoogleAuthUtil.getToken(appContext,
                                AppSettings.getGoogleAccountName(),
                                "oauth2:https://picasaweb.google.com/data/");
                        AppSettings.setGoogleAccountToken(authToken);
                        AppSettings.setGoogleAccount(true);
                        new PicasaAlbumTask(-1, true).execute();
                    } catch (IOException transientEx) {
                        return null;
                    } catch (UserRecoverableAuthException e) {
                        return null;
                    } catch (GoogleAuthException authEx) {
                        return null;
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    return null;
                }
            }.execute();
        }
    }
}

From source file:org.andstatus.app.account.AccountSettingsActivity.java

/** 
 * Mark the action completed, close this activity and go back to the proper screen.
 * Return result to the caller if necessary.
 * See also {@link com.android.email.activity.setup.AccountSetupBasics.finish}
 * // w w w.  j  a v a  2 s  . c o  m
 * @return
 */
private void closeAndGoBack() {
    // Explicitly save MyAccount only on "Back key" 
    state.builder.save();
    String message = "";
    state.actionCompleted = true;
    overrideBackActivity = true;
    if (state.authenticatiorResponse != null) {
        // We should return result back to AccountManager
        overrideBackActivity = false;
        if (state.actionSucceeded) {
            if (state.builder.isPersistent()) {
                // Pass the new/edited account back to the account manager
                Bundle result = new Bundle();
                result.putString(AccountManager.KEY_ACCOUNT_NAME, state.getAccount().getAccountName());
                result.putString(AccountManager.KEY_ACCOUNT_TYPE, AuthenticatorService.ANDROID_ACCOUNT_TYPE);
                state.authenticatiorResponse.onResult(result);
                message += "authenticatiorResponse; account.name=" + state.getAccount().getAccountName() + "; ";
            }
        } else {
            state.authenticatiorResponse.onError(AccountManager.ERROR_CODE_CANCELED, "canceled");
        }
    }
    // Forget old state
    state.forget();
    if (!mIsFinishing) {
        MyLog.v(this, "finish: action=" + state.getAccountAction() + "; " + message);
        mIsFinishing = true;
        finish();
    }
}