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.example.android.cloudnotes.ui.HomeActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case CHOOSE_ACCOUNT: if (resultCode == RESULT_OK && data != null && data.hasExtra(AccountManager.KEY_ACCOUNT_NAME)) { final String syncAccount = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); if (!TextUtils.isEmpty(syncAccount)) { SharedPreferences.Editor prefs = getSharedPreferences(KEY_PREFS, MODE_PRIVATE).edit(); prefs.putString(AccountManager.KEY_ACCOUNT_NAME, syncAccount); prefs.commit();// ww w. j a v a2s . co m // resume syncing startDriveSync(); } } break; case AUTH_APP: if (resultCode == RESULT_OK) { // resume syncing startDriveSync(); } break; default: break; } }
From source file:com.battlelancer.seriesguide.backend.CloudSetupFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case CloudSetupActivity.REQUEST_ACCOUNT_PICKER: { if (data != null && data.getExtras() != null) { String accountName = data.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME); if (!TextUtils.isEmpty(accountName)) { setupHexagon(accountName); }/*from www . j a v a2s . com*/ } break; } } }
From source file:com.ntsync.android.sync.activities.KeyPasswordActivity.java
/** * Called when KeyPassword was set.//from www . java2s.co m * * @param result * the confirmCredentials result. */ private void finishSetKeyPassword() { Log.i(TAG, "finishSetKeyPassword()"); final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE); setResult(RESULT_OK, intent); Account account = new Account(mUsername, Constants.ACCOUNT_TYPE); ContentResolver.requestSync(account, Constants.CONTACT_AUTHORITY, new Bundle()); // Remove notification clearNotification(account.name); finish(); }
From source file:org.ohmage.auth.Authenticator.java
@Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) throws NetworkErrorException { // Extract the email and refresh_token from the Account Manager, and ask // the server for a new refresh_token. String authToken = am.peekAuthToken(account, authTokenType); // Lets give another try to authenticate the user AccessToken token = null;//w ww .j a va 2 s.c om UserRecoverableAuthException userRecoverableAuthException = null; if (TextUtils.isEmpty(authToken)) { final String refreshToken = am.getPassword(account); Log.i(TAG, "Auth token is null"); if (refreshToken != null) { Log.i(TAG, "Refresh Token"); try { // If the account credentials have not gone to the server yet we saved the // password for the user if (Boolean.parseBoolean(am.getUserData(account, USE_PASSWORD))) { token = ohmageService.getAccessToken(account.name, refreshToken); if (token != null) { am.setUserData(account, Authenticator.USE_PASSWORD, String.valueOf(false)); am.setUserData(account, Authenticator.USER_ID, token.getUserId()); } } else { // refresh token if (Ohmage.USE_DSU_DATAPOINTS_API) { Log.i(TAG, "Refresh Token with DSU"); token = ohmageService.refreshAccessToken(refreshToken, "refresh_token"); } else { token = ohmageService.getAccessToken(refreshToken); } } } catch (AuthenticationException e) { // This will happen if the refresh token was already used, or it was // invalidated or something // We can try getting the token from google String googleAccount = am.getUserData(account, USER_DATA_GOOGLE_ACCOUNT); if (googleAccount != null) { try { token = getTokenFromGoogle(googleAccount); Log.i(TAG, token.toString()); } catch (UserRecoverableAuthException e1) { userRecoverableAuthException = e1; } } } catch (RetrofitError e) { if (e.getResponse() != null && e.getResponse().getStatus() == 409) { // The user hasn't activated their account by clicking the link final Bundle bundle = new Bundle(); bundle.putString(AccountManager.KEY_AUTH_FAILED_MESSAGE, Ohmage.app().getString(R.string.account_not_activated)); bundle.putParcelable(AccountManager.KEY_INTENT, new Intent(mContext, AccountNotActivatedDialog.class)); return bundle; } else { throw new NetworkErrorException(); } } catch (Exception e) { Log.e(TAG, "", e); } } } // If we get an authToken - we return it if (token != null) { am.setPassword(account, token.getRefreshToken()); authToken = token.getAccessToken(); } if (!TextUtils.isEmpty(authToken)) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); result.putString(AccountManager.KEY_AUTHTOKEN, authToken); return result; } // If we get here, then we couldn't access the user's password - so we // need to re-prompt them for their credentials. We do that by creating // an intent to display our AuthenticatorActivity. final Intent intent = new Intent(mContext, AuthenticatorActivity.class); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); intent.putExtra(AuthenticatorActivity.EXTRA_FROM_AUTHENTICATOR, true); intent.putExtra(AuthenticatorActivity.EXTRA_HANDLE_USER_RECOVERABLE_ERROR, userRecoverableAuthException); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; }
From source file:com.pindroid.authenticator.AuthenticatorActivity.java
/** * //from ww w. j a va 2 s.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(String authToken) { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); final int synctime = Integer.parseInt(settings.getString("pref_synctime", "0")); final Account account = new Account(mUsername, Constants.ACCOUNT_TYPE); if (mRequestNewAccount) { mAccountManager.addAccountExplicitly(account, null, null); ContentResolver.setSyncAutomatically(account, BookmarkContentProvider.AUTHORITY, true); if (synctime != 0) { SyncUtils.addPeriodicSync(BookmarkContentProvider.AUTHORITY, Bundle.EMPTY, synctime, this); } } mAccountManager.setAuthToken(account, Constants.AUTHTOKEN_TYPE, authToken); final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE); intent.putExtra(AccountManager.KEY_AUTHTOKEN, authToken); setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); finish(); }
From source file:be.evias.cloudLogin.cloudLoginMainActivity.java
private void processLogoutServerSide(final Account account) { new AsyncTask<String, Void, Intent>() { @Override//from ww w. j av a 2s .com protected Intent doInBackground(String... params) { Bundle data = new Bundle(); try { sServerAuthenticate.userSignOut(mContext, account.name); data.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); Log.d("cloudLogin", "cloudloginMainActivity/logoutAccount: userSignOut successful."); showMessage(mContext.getString(R.string.message_logout_success), Toast.LENGTH_SHORT); } catch (Exception e) { Log.d("cloudLogin", "cloudloginMainActivity/logoutAccount: userSignOut error."); e.printStackTrace(); data.putString(KEY_ERROR_MESSAGE, e.getMessage()); } final Intent res = new Intent(); res.putExtras(data); return res; } @Override protected void onPostExecute(Intent intent) { if (intent.hasExtra(KEY_ERROR_MESSAGE)) Toast.makeText(getBaseContext(), intent.getStringExtra(KEY_ERROR_MESSAGE), Toast.LENGTH_SHORT) .show(); else finishLogout(intent); } }.execute(); }
From source file:com.lumysoft.lumyd.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { // Choose what to do based on the request code switch (requestCode) { // If the request code matches the code sent in onConnectionFailed case LumydUtils.CONNECTION_FAILURE_RESOLUTION_REQUEST: switch (resultCode) { // If Google Play services resolved the problem case Activity.RESULT_OK: Log.d(LumydUtils.APPTAG, getString(R.string.resolved)); break; default:/*w w w . j av a2s . c o m*/ Log.d(LumydUtils.APPTAG, getString(R.string.no_resolution)); break; } case LumydUtils.REQUEST_ACCOUNT_PICKER: if (intent != null && intent.getExtras() != null) { String accountName = intent.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME); if (accountName != null) { //Save it in prefs and credential SharedPreferences.Editor editor = mSettings.edit(); editor.putString(LumydUtils.PREF_ACCOUNT_NAME, accountName); editor.commit(); mCredential.setSelectedAccountName(accountName); // User is authorized. } } break; default: // Report that this Activity received an unknown requestCode Log.d(LumydUtils.APPTAG, getString(R.string.unknown_activity_request_code, requestCode)); break; } }
From source file:com.jaspersoft.android.jaspermobile.ui.view.activity.NavigationActivity.java
@OnActivityResult(NEW_ACCOUNT) final void newAccountAction(int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { String profileName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); Profile profile = Profile.create(profileName); mActionListener.activateProfile(profile); }//from ww w .j a va 2s. c om }
From source file:com.google.android.apps.watchme.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case REQUEST_GMS_ERROR_DIALOG: break;/*from ww w. ja v a2s . co m*/ case REQUEST_GOOGLE_PLAY_SERVICES: if (resultCode == Activity.RESULT_OK) { haveGooglePlayServices(); } else { checkGooglePlayServicesAvailable(); } break; case REQUEST_AUTHORIZATION: if (resultCode != Activity.RESULT_OK) { chooseAccount(); } break; case REQUEST_ACCOUNT_PICKER: if (resultCode == Activity.RESULT_OK && data != null && data.getExtras() != null) { String accountName = data.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME); if (accountName != null) { mChosenAccountName = accountName; credential.setSelectedAccountName(accountName); saveAccount(); } } break; case REQUEST_STREAMER: if (resultCode == Activity.RESULT_OK && data != null && data.getExtras() != null) { String broadcastId = data.getStringExtra(YouTubeApi.BROADCAST_ID_KEY); if (broadcastId != null) { new EndEventTask().execute(broadcastId); } } break; } }
From source file:sk.mpage.androidsample.drawerwithauthenticator.MainActivity.java
private void getTokenForAccountCreateIfNeeded(String accountType, String authTokenType) { final AccountManagerFuture<Bundle> future = mAccountManager.getAuthTokenByFeatures(accountType, authTokenType, null, this, null, null, new AccountManagerCallback<Bundle>() { @Override// w w w . ja va2 s . c o m public void run(AccountManagerFuture<Bundle> future) { Bundle bnd = null; try { bnd = future.getResult(); authToken = bnd.getString(AccountManager.KEY_AUTHTOKEN); if (authToken != null) { String accountName = bnd.getString(AccountManager.KEY_ACCOUNT_NAME); mConnectedAccount = new Account(accountName, AccountGeneral.ACCOUNT_TYPE); //callback after connected setAppUIForUser(); } else { getTokenForAccountCreateIfNeeded(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS); } } catch (Exception e) { e.printStackTrace(); } } }, null); }