List of usage examples for android.accounts AccountManager KEY_ACCOUNT_NAME
String KEY_ACCOUNT_NAME
To view the source code for android.accounts AccountManager KEY_ACCOUNT_NAME.
Click Source Link
From source file:de.msal.shoutemo.connector.GetPostsService.java
@Override public void onCreate() { super.onCreate(); broadcaster = LocalBroadcastManager.getInstance(this); mAccountManager = AccountManager.get(this); Account[] acc = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE); /* No account; push the user into adding one */ if (acc.length == 0) { Log.v(TAG, "No suitable account found, directing user to add one."); mAccountManager.addAccount(AccountAuthenticator.ACCOUNT_TYPE, null, null, new Bundle(), null, new AccountManagerCallback<Bundle>() { @Override/*w ww .j av a 2 s .c om*/ public void run(AccountManagerFuture<Bundle> result) { Bundle bundle; try { bundle = result.getResult(); } catch (OperationCanceledException e) { e.printStackTrace(); return; } catch (AuthenticatorException e) { e.printStackTrace(); return; } catch (IOException e) { e.printStackTrace(); return; } /* no accounts saved, yet; ask the user for credentials */ Intent launch = bundle.getParcelable(AccountManager.KEY_INTENT); if (launch != null) { launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(launch); return; } mAccount = new Account(bundle.getString(AccountManager.KEY_ACCOUNT_NAME), bundle.getString(AccountManager.KEY_ACCOUNT_TYPE)); Log.v(TAG, "Added account " + mAccount.name + "; now fetching new posts."); startGetPostsTask(); } }, null); } else { mAccount = acc[0]; startGetPostsTask(); } }
From source file:com.kinvey.sample.signin.GoogleLoginActivity.java
private void finishLogin(String authToken, String password) { final Account account = new Account(authToken, UserLogin.ACCOUNT_TYPE); Bundle userData = new Bundle(); userData.putString(UserLogin.LOGIN_TYPE_KEY, PARAM_LOGIN_TYPE_GOOGLE); mAccountManager.addAccountExplicitly(account, password, userData); final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, authToken); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, UserLogin.ACCOUNT_TYPE); setResult(RESULT_OK, intent);/*from ww w . j a va2 s . c o m*/ finish(); }
From source file:be.evias.cloudLogin.cloudLoginRunPointActivity.java
/** * Add new account to the account manager for the cloudLogin * account type./*from w w w . ja v a 2 s . c om*/ * * @param accountType String * @param authTokenType String */ private void addNewAccount(String accountType, String authTokenType) { final AccountManagerFuture<Bundle> future = mAccountManager.addAccount(accountType, authTokenType, null, null, this, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle bnd = future.getResult(); showMessage(getBaseContext().getString(R.string.message_account_created), Toast.LENGTH_SHORT); Log.d("cloudLogin", "AddNewAccount Bundle is " + bnd); final Account account = new Account(bnd.getString(AccountManager.KEY_ACCOUNT_NAME), bnd.getString(AccountManager.KEY_ACCOUNT_TYPE)); SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean("cloudlogin_active_account", true); editor.putString("cloudlogin_active_account_name", account.name); editor.commit(); displayNavigationDrawer(bnd, account); } catch (Exception e) { e.printStackTrace(); showMessage(e.getMessage(), Toast.LENGTH_LONG); SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean("cloudlogin_active_account", false); editor.commit(); } } }, null); }
From source file:net.xisberto.phonetodesktop.ui.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_ACCOUNT_PICKER: Utils.log("Result from Account Picker"); if (resultCode == RESULT_OK && data != null && data.hasExtra(AccountManager.KEY_ACCOUNT_NAME)) { String accountName = data.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME); Utils.log("Saving account " + accountName); preferences.saveAccountName(accountName); saveListId();//from ww w . j a va2 s.c o m updateMainLayout(true); } else { updateMainLayout(false); } break; case REQUEST_GOOGLE_PLAY_SERVICES: Utils.log("Return from Play Services error"); break; case REQUEST_AUTHORIZATION: Utils.log("Result from Authorization"); if (resultCode == RESULT_OK) { Utils.log("starting saveListId"); updateMainLayout(true); saveListId(); } else { updateMainLayout(false); } break; default: break; } }
From source file:org.jboss.aerogear.cordova.oauth2.OauthGoogleServicesIntentHelper.java
public void onActivityResult(int requestCode, int resultCode, final Intent data) { if (callbackContext != null) { try {/*from ww w.j a v a 2s . c om*/ if (requestCode == REQUEST_CODE_PICK_ACCOUNT) { if (resultCode == Activity.RESULT_OK) { String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); Log.i(TAG, "account:" + accountName); getToken(accountName); } else { callbackContext.error("plugin failed to get account"); } } else if (requestCode == REQUEST_AUTHORIZATION) { if (resultCode == Activity.RESULT_OK) { String token = data.getStringExtra(KEY_AUTH_TOKEN); callbackContext.success(token); } else { callbackContext.error("plugin failed to get token"); } } else { Log.i(TAG, "Unhandled activityResult. requestCode: " + requestCode + " resultCode: " + resultCode); } } catch (Exception e) { callbackContext.error("Plugin failed to get email: " + e.toString()); Log.e(TAG, "Exception: " + e.toString()); } } else { Log.d(TAG, "No callback to go to!"); } }
From source file:com.google.devrel.samples.memedroid.app.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQ_CREATE_MEME && resultCode == RESULT_OK) { // MEME CREATION RESPONSE. Intent intent = new Intent(MemeService.ACTION_CREATE, null, this, MemeService.class); intent.putExtra(Constants.MEME_IMAGE_URL, data.getStringExtra(Constants.MEME_IMAGE_URL)); intent.putExtra(Constants.MEME_TEXT, data.getStringExtra(Constants.MEME_TEXT)); intent.putExtra(Constants.MEME_CREDENTIAL, getAccountName()); intent.putExtra("receiver", mReceiver); startService(intent);//from w ww. j av a 2 s .co m this.setProgressBarIndeterminateVisibility(true); } else if (requestCode == REQ_CHOOSE_ACCOUNT && resultCode == RESULT_OK) { // ACCOUNT CHOOSER RESPONSE. String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); storeAccountName(accountName); invalidateOptionsMenu(); if (mPendingVote != null) { triggerVoteCreation(mPendingVote); mPendingVote = null; } else { triggerCreation(); } } }
From source file:edu.mit.mobile.android.locast.accounts.Authenticator.java
/** * {@inheritDoc}/*from ww w.ja v a2s . com*/ */ @Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) { if (!authTokenType.equals(AuthenticationService.AUTHTOKEN_TYPE)) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType"); return result; } final AccountManager am = AccountManager.get(mContext); final String password = am.getPassword(account); if (password != null) { final Bundle accountData = onlineConfirmPassword(account, password); if (accountData != null) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, AuthenticationService.ACCOUNT_TYPE); result.putString(AccountManager.KEY_AUTHTOKEN, password); return result; } } // the password was missing or incorrect, return an Intent to an // Activity that will prompt the user for the password. final Intent intent = new Intent(mContext, AuthenticatorActivity.class); intent.putExtra(AuthenticatorActivity.EXTRA_USERNAME, account.name); intent.putExtra(AuthenticatorActivity.EXTRA_AUTHTOKEN_TYPE, authTokenType); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; }
From source file:com.google.cloud.backend.android.CloudBackendActivity.java
/** * Handles callback from Intents like authorization request or account * picking.// ww w . j av a2 s.c om */ @Override protected final 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:edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticator.java
/** * {@inheritDoc}/* w ww. j a va 2s . c om*/ */ @Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) { if (!authTokenType.equals(getAuthTokenType())) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType"); return result; } final AccountManager am = AccountManager.get(mContext); final String password = am.getPassword(account); if (password != null) { final Bundle accountData = onlineConfirmPassword(account, password); if (accountData != null) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, getAccountType()); result.putString(AccountManager.KEY_AUTHTOKEN, password); return result; } } // the password was missing or incorrect, return an Intent to an // Activity that will prompt the user for the password. final Intent intent = getAuthenticator(mContext); intent.putExtra(AbsLocastAuthenticatorActivity.EXTRA_USERNAME, account.name); intent.putExtra(AbsLocastAuthenticatorActivity.EXTRA_AUTHTOKEN_TYPE, authTokenType); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; }
From source file:com.nextgis.maplibui.activity.NGWLoginActivity.java
@Override public void onAddAccount(Account account, String token, boolean accountAdded) { if (null != account) { mResultBundle = new Bundle(); if (accountAdded) { mResultBundle.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); mResultBundle.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); mResultBundle.putString(AccountManager.KEY_AUTHTOKEN, token); } else {/*from ww w .j a v a 2 s .c o m*/ mResultBundle.putString(AccountManager.KEY_ERROR_MESSAGE, getString(R.string.account_already_exists)); } } setResult(RESULT_OK); finish(); }