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:com.nbos.phonebook.sync.authenticator.AuthenticatorActivity.java
/** * //from ww w. j ava 2s . c o m * 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. * * @param the confirmCredentials result. */ protected void finishLogin() { Log.i(tag, "finishLogin()"); final Account account = new Account(mUsername, Constants.ACCOUNT_TYPE); if (mRequestNewAccount) { mAccountManager.addAccountExplicitly(account, mPassword, null); mAccountManager.setUserData(account, Constants.PHONE_NUMBER_KEY, countryCode + mPhone); // Set contacts sync for this account. ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true); } else { mAccountManager.setPassword(account, mPassword); } final Intent intent = new Intent(); mAuthtoken = mPassword; intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE); if (mAuthtokenType != null && mAuthtokenType.equals(Constants.AUTHTOKEN_TYPE)) intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAuthtoken); Db.deleteServerData(getApplicationContext()); setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); finish(); }
From source file:amhamogus.com.daysoff.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case REQUEST_GOOGLE_PLAY_SERVICES: if (resultCode != RESULT_OK) { mOutputText.setText("This app requires Google Play Services. Please " + "install Google Play Services on your device " + "and relaunch this app."); } else {//from w ww.jav a 2 s . co m getCalendarList(); } break; case REQUEST_ACCOUNT_PICKER: if (resultCode == RESULT_OK && data != null && data.getExtras() != null) { String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); // Add users' account name to shared preferences if (accountName != null) { SharedPreferences settings = getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); editor.putString(PREF_ACCOUNT_NAME, accountName); editor.apply(); mCredential.setSelectedAccountName(accountName); mList = mList.newInstance(1); fragmentManager.beginTransaction().add(R.id.list_wrapper, mList, "list").commit(); } } break; case REQUEST_AUTHORIZATION: if (resultCode == RESULT_OK) { getCalendarList(); } break; } }
From source file:uk.ac.horizon.artcodes.activity.NavigationActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_PICK_ACCOUNT) { if (resultCode == RESULT_OK) { if (data != null) { if (data.hasExtra(AccountManager.KEY_ACCOUNT_NAME)) { String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); if (accountName != null) { tryGoogleAccount(accountName, null); }/*from w w w .ja v a 2 s . co m*/ } } } } else if (requestCode == REQUEST_CODE_SIGN_IN) { final GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); if (result.getSignInAccount() != null) { tryGoogleAccount(result.getSignInAccount().getEmail(), result.getSignInAccount().getDisplayName()); } } }
From source file:pt.up.mobile.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. We store the * authToken that's returned from the server as the 'password' for this * account - so we're never storing the user's actual password locally. * // w w w . jav a 2s. c o m * @param result * the confirmCredentials result. */ @TargetApi(8) private void finishLogin(final User user) { Log.i(TAG, "finishLogin()"); new Thread(new Runnable() { @Override public void run() { final Account account = new Account(mUsername, Constants.ACCOUNT_TYPE); if (mRequestNewAccount) { final ContentValues values = new ContentValues(); values.put(SigarraContract.Users.CODE, user.getUserCode()); values.put(SigarraContract.Users.TYPE, user.getType()); values.put(SigarraContract.Users.ID, account.name); getContentResolver().insert(SigarraContract.Users.CONTENT_URI, values); // Set contacts sync for this account. if (!mAccountManager.addAccountExplicitly(account, mPassword, Bundle.EMPTY)) { getContentResolver().delete(SigarraContract.Users.CONTENT_URI, SigarraContract.Users.PROFILE, SigarraContract.Users.getUserSelectionArgs(account.name)); finish(); } String syncIntervalValue = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()) .getString(getString(R.string.key_sync_interval), Integer.toString(getResources().getInteger(R.integer.default_sync_interval))); String syncNotIntervalValue = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()) .getString(getString(R.string.key_notifications_sync_interval), Integer.toString(getResources().getInteger(R.integer.default_sync_interval))); ContentResolver.setSyncAutomatically(account, SigarraContract.CONTENT_AUTHORITY, true); ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { ContentResolver.addPeriodicSync(account, SigarraContract.CONTENT_AUTHORITY, Bundle.EMPTY, Integer.parseInt(syncIntervalValue) * 3600); ContentResolver.addPeriodicSync(account, SigarraContract.CONTENT_AUTHORITY, SigarraSyncAdapterUtils.getNotificationsPeriodicBundle(), Integer.parseInt(syncNotIntervalValue) * 3600); } else { PeriodicSyncReceiver.cancelPreviousAlarms(getApplicationContext(), account, SigarraContract.CONTENT_AUTHORITY, Bundle.EMPTY); PeriodicSyncReceiver.addPeriodicSync(getApplicationContext(), account, SigarraContract.CONTENT_AUTHORITY, Bundle.EMPTY, Integer.parseInt(syncIntervalValue) * 3600); PeriodicSyncReceiver.addPeriodicSync(getApplicationContext(), account, SigarraContract.CONTENT_AUTHORITY, SigarraSyncAdapterUtils.getNotificationsBundle(), Integer.parseInt(syncNotIntervalValue) * 3600); } } else { mAccountManager.setPassword(account, user.getPassword()); } final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE); setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); finish(); } }).start(); }
From source file:com.zuluindia.watchpresenter.MainActivity.java
@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) { String accountName = data.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME); if (accountName != null) { Log.d(Constants.LOG_TAG, "User picked. Account name: " + accountName); setSelectedAccountName(accountName); SharedPreferences.Editor editor = settings.edit(); editor.putString(Constants.PREF_ACCOUNT_NAME, accountName); editor.commit();// w w w . j av a 2s .c om final int lastTutorialShown = settings.getInt(Constants.PREF_LAST_TUTORIAL_SHOWN, 0); if (lastTutorialShown < TUTORIAL_VERSION) { launchTutorial(); } checkAndUpdateRegistration(); } else { alertAndClose(); } } else { alertAndClose(); } break; case TUTORIAL_ACTIVITY: SharedPreferences.Editor editor = settings.edit(); editor.putInt(Constants.PREF_LAST_TUTORIAL_SHOWN, TUTORIAL_VERSION); editor.putInt(Constants.PREF_LAST_UPDATES_SHOWN, versionCode); editor.commit(); break; } }
From source file:edu.mit.mobile.android.locast.accounts.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. * * @param userData/*from www. j a v a2s . c o m*/ * TODO * @param the * confirmCredentials result. */ protected void finishLogin(Bundle userData) { Log.i(TAG, "finishLogin()"); // ensure that there isn't a demo account sticking around. // TODO this is NOT the place where this code belongs. Find it a better home if (Authenticator.isDemoMode(this)) { Log.d(TAG, "cleaning up demo mode account..."); ContentResolver.cancelSync(Authenticator.getFirstAccount(this), MediaProvider.AUTHORITY); mAccountManager.removeAccount( new Account(Authenticator.DEMO_ACCOUNT, AuthenticationService.ACCOUNT_TYPE), new AccountManagerCallback<Boolean>() { @Override public void run(AccountManagerFuture<Boolean> arg0) { try { if (arg0.getResult()) { final ContentValues cv = new ContentValues(); // invalidate all the content to force a sync. // this is to ensure that items which were marked favorite get set as // such. cv.put(Cast._SERVER_MODIFIED_DATE, 0); cv.put(Cast._MODIFIED_DATE, 0); getContentResolver().update(Cast.CONTENT_URI, cv, null, null); if (Constants.DEBUG) { Log.d(TAG, "reset all cast modified dates to force a reload"); } } } catch (final OperationCanceledException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final AuthenticatorException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }, null); } final Account account = new Account(mUsername, AuthenticationService.ACCOUNT_TYPE); if (mRequestNewAccount) { mAccountManager.addAccountExplicitly(account, mPassword, userData); // Automatically enable sync for this account ContentResolver.setSyncAutomatically(account, MediaProvider.AUTHORITY, true); } else { mAccountManager.setPassword(account, mPassword); } final Intent intent = new Intent(); mAuthtoken = mPassword; intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AuthenticationService.ACCOUNT_TYPE); if (mAuthtokenType != null && mAuthtokenType.equals(AuthenticationService.AUTHTOKEN_TYPE)) { intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAuthtoken); } setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); finish(); }
From source file:com.bangz.shotrecorder.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { //super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case REQUEST_INSTALL_GOOGLEPLAYSERVICE: if (resultCode == RESULT_CANCELED) { Toast.makeText(this, R.string.must_install_google_play, Toast.LENGTH_LONG).show(); }/*from ww w . j a v a 2 s .c o m*/ break; case REQUEST_ACCOUNT_PICKER: if (resultCode == RESULT_OK && data != null && data.getExtras() != null) { String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); if (accountName != null) { credential.setSelectedAccountName(accountName); googleDriveService = getDriveService(credential); if (backup_or_restore == REQUEST_FOR_BACKUP_GOOGLE_DRIVE) saveFileToDrive(); else if (backup_or_restore == REQUEST_FOR_RESTORE_GOOGLE_DRIVE) { restoreFileFromDrive(); } } } break; case REQUEST_AUTHORIZATION: if (resultCode == RESULT_OK) { if (backup_or_restore == REQUEST_FOR_BACKUP_GOOGLE_DRIVE) saveFileToDrive(); else if (backup_or_restore == REQUEST_FOR_RESTORE_GOOGLE_DRIVE) restoreFileFromDrive(); } else { startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER); } break; } }
From source file:edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticatorActivity.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. * * @param userData//from w w w . j a va 2 s . c om * TODO * @param the * confirmCredentials result. */ protected void finishLogin(Bundle userData) { if (BuildConfig.DEBUG) { Log.i(TAG, "finishLogin()"); } final Account account = createAccount(mUsername); if (mRequestNewAccount) { mAccountManager.addAccountExplicitly(account, mPassword, userData); // Automatically enable sync for this account ContentResolver.setSyncAutomatically(account, getAuthority(), true); } else { mAccountManager.setPassword(account, mPassword); } final Intent intent = new Intent(); mAuthtoken = mPassword; intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, getAccountType()); if (mAuthtokenType != null && mAuthtokenType.equals(getAuthtokenType())) { intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAuthtoken); } setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); finish(); }
From source file:org.xwiki.android.authenticator.auth.AuthenticatorActivity.java
public void finishLogin(Intent intent) { Log.d(TAG, "> finishLogin"); //before add new account, clear old account data. clearOldAccount();// w ww .j a va 2s .com //get values String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); String accountPassword = intent.getStringExtra(PARAM_USER_PASS); String accountServer = intent.getStringExtra(PARAM_USER_SERVER); // Creating the account on the device and setting the auth token we got // (Not setting the auth token will cause another call to the server to authenticate the user) Log.d(TAG, "finishLogin > addAccountExplicitly" + " " + intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE)); final Account account = new Account(accountName, Constants.ACCOUNT_TYPE); mAccountManager.addAccountExplicitly(account, accountPassword, null); mAccountManager.setUserData(account, AccountManager.KEY_USERDATA, accountName); mAccountManager.setUserData(account, AccountManager.KEY_PASSWORD, accountPassword); mAccountManager.setUserData(account, AuthenticatorActivity.PARAM_USER_SERVER, accountServer); //grant permission if adding user from the third-party app (UID,PackageName); String packaName = getIntent().getStringExtra(PARAM_APP_PACKAGENAME); int uid = getIntent().getIntExtra(PARAM_APP_UID, 0); Log.d(TAG, packaName + ", " + getPackageName()); //only if adding account from the third-party apps exclude android.uid.system, this will execute to grant permission and set token if (!packaName.contains("android.uid.system")) { AppContext.addAuthorizedApp(uid, packaName); String authToken = intent.getStringExtra(AccountManager.KEY_AUTHTOKEN); if (!TextUtils.isEmpty(authToken)) { String authTokenType = getIntent().getStringExtra(KEY_AUTH_TOKEN_TYPE); mAccountManager.setAuthToken(account, authTokenType, authToken); } } //return value to AccountManager Intent intentReturn = new Intent(); intentReturn.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE); intentReturn.putExtra(AccountManager.KEY_ACCOUNT_NAME, accountName); setAccountAuthenticatorResult(intentReturn.getExtras()); setResult(RESULT_OK, intentReturn); Log.d(TAG, ">" + "finish return"); // in SettingSyncViewFlipper this activity finish; }
From source file:org.fathens.cordova.googleplus.GooglePlusConnect.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); Log.i(TAG, "onActivityResult:" + requestCode); switch (requestCode) { case REQUEST_PICK_ACCOUNT: if (resultCode == Activity.RESULT_OK) { accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); obtainToken();/* w ww. j a v a 2 s .co m*/ } else { currentCallback.error("No account selected"); } break; case REQUEST_AUTH_RECOVER: if (resultCode == Activity.RESULT_OK) { obtainToken(); } else { currentCallback.error("Cannot authrorize"); } break; case REQUEST_PCLIENT_RECOVER: if (resultCode == Activity.RESULT_OK && pClient != null) { pClient.connect(); } else { currentCallback.error("PlusClient: Failed to retry connection"); } break; case REQUEST_GCLIENT_RECOVER: if (resultCode == Activity.RESULT_OK && pClient != null) { gClient.connect(); } else { currentCallback.error("GoogleApiClient: Failed to retry connection"); } break; default: break; } }