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.google.ytdl.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_GMS_ERROR_DIALOG: break;// w w w .ja v a 2 s .co m case REQUEST_PICK_ACCOUNT: if (resultCode == RESULT_OK) { mChosenAccountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); tryAuthenticate(); } else { // TODO } break; case REQUEST_AUTHENTICATE: if (resultCode == RESULT_OK) { tryAuthenticate(); } setProgressBarIndeterminateVisibility(false); break; case RESULT_PICK_IMAGE_CROP: if (resultCode == RESULT_OK) { mFileURI = data.getData(); mVideoData = null; // TODO } break; case RESULT_VIDEO_CAP: if (resultCode == RESULT_OK) { mFileURI = data.getData(); mVideoData = null; // TODO } break; } super.onActivityResult(requestCode, resultCode, data); }
From source file:com.owncloud.android.ui.activity.ManageAccountsActivity.java
@Override public void createAccount() { AccountManager am = AccountManager.get(getApplicationContext()); am.addAccount(MainApp.getAccountType(), null, null, null, this, new AccountManagerCallback<Bundle>() { @Override//from w ww . ja v a2s.c o m public void run(AccountManagerFuture<Bundle> future) { if (future != null) { try { Bundle result = future.getResult(); String name = result.getString(AccountManager.KEY_ACCOUNT_NAME); AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), name); mAccountListAdapter = new AccountListAdapter(ManageAccountsActivity.this, getAccountListItems(), mTintedCheck); mListView.setAdapter(mAccountListAdapter); runOnUiThread(new Runnable() { @Override public void run() { mAccountListAdapter.notifyDataSetChanged(); } }); } catch (OperationCanceledException e) { Log_OC.d(TAG, "Account creation canceled"); } catch (Exception e) { Log_OC.e(TAG, "Account creation finished in exception: ", e); } } } }, mHandler); }
From source file:com.androidexperiments.sprayscape.unitydriveplugin.GoogleDriveUnityPlayerActivity.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { Log.i(TAG, "onActivityResult(" + requestCode + ", " + resultCode + ", " + data + ")"); UnityPlayer.UnitySendMessage("OnActivityResultListener", "OnActivityResult", requestCode + "," + resultCode + "," + data); switch (requestCode) { case REQUEST_CODE_ACCOUNT_SELECTED: { if (resultCode == RESULT_OK) { final String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); String accountType = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE); SharedPreferences prefs = getPreferences(MODE_PRIVATE); final SharedPreferences.Editor e = prefs.edit(); e.putString(GOOGLE_ACCOUNT_NAME, accountName); e.apply();//from w w w . ja va2 s . co m Log.i(TAG, "user selected account: " + accountName + " type: " + accountType + " saved to shared preferences"); account = new Account(accountName, accountType); // TODO: maybe don't assume the user was trying to upload? // try uploading again //uploadFile(lastDriveFolderName, lastDriveFileName, lastLocalPath, lastCallbackObjectName); driveService = initDriveServiceFromAccount(account, lastCallbackObjectName); } else { // user cancel the account picker without selecting.... UnityPlayer.UnitySendMessage(lastCallbackObjectName, CALLBACK_METHOD_DRIVE_ACCOUNT_SELECTION_CANCELED, "" + resultCode); } break; } case REQUEST_CODE_RECOVER_FROM_TOKEN_AUTHENTICATE: { // if(resultCode == RESULT_OK){ fetchAuthToken(lastCallbackObjectName); // } else { // clearAccount(); // UnityPlayer.UnitySendMessage(lastCallbackObjectName, CALLBACK_METHOD_DRIVE_AUTH_CANCELED, "" + resultCode); // } break; } case REQUEST_CODE_RECOVER_FROM_DRIVE_UPLOAD_ERROR: { if (resultCode == RESULT_OK) { // user fixed the authentication problem try upload again uploadFile(lastDriveFolderName, lastDriveFileName, lastLocalPath, lastCallbackObjectName); } else { // this happens when the user deny's the authorization // we will clear the auth data in-case they wanted to switch accounts on the next try clearAccount(); UnityPlayer.UnitySendMessage(lastCallbackObjectName, CALLBACK_METHOD_DRIVE_AUTH_CANCELED, "" + resultCode); } break; } default: super.onActivityResult(requestCode, resultCode, data); } }
From source file:be.evias.cloudLogin.cloudLoginRunPointActivity.java
private void displayNavigationDrawer(Bundle bnd, Account act) { Intent act_main = new Intent(getBaseContext(), cloudLoginMainActivity.class); act_main.putExtra(AccountManager.KEY_ACCOUNT_NAME, act.name); startActivity(act_main);/* w ww . j a va2 s. co m*/ }
From source file:com.sintef_energy.ubisolar.activities.DrawerActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); if (requestCode == LOGIN_CALL_ID) { if (resultCode == Activity.RESULT_OK) { Log.v(TAG, "Login was successful. Starting to attain session data."); startFacebookLogin(null);//from w w w. j ava2s . com // Find the account Account[] accounts = getAccounts(getApplicationContext(), ACCOUNT_TYPE); for (Account account : accounts) { if (account.name.equals(data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME))) { mAccount = account; break; } } if (mAccount == null) { Log.e(TAG, "Account creation somehow failed to make an account."); return; } /* The same as ticking allow sync */ ContentResolver.setSyncAutomatically(mAccount, AUTHORITY_PROVIDER, true); /* Request a sync operation */ Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); //Do sync regardless of settings bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); //Force sync immediately ContentResolver.requestSync(mAccount, AUTHORITY_PROVIDER, bundle); /* Update all -1 users to the current user id. */ AccountManager accountManager = (AccountManager) getApplicationContext() .getSystemService(ACCOUNT_SERVICE); String facebookUID = accountManager.getUserData(mAccount, Global.DATA_FB_UID); ContentValues values = new ContentValues(); values.put(DeviceModel.DeviceEntry.COLUMN_USER_ID, facebookUID); values.put(DeviceModel.DeviceEntry.COLUMN_LAST_UPDATED, System.currentTimeMillis() / 1000L); getContentResolver().update(EnergyContract.Devices.CONTENT_URI, values, EnergyContract.Devices.COLUMN_USER_ID + "=?", new String[] { "-1" }); //Publish a post saying you started using Wattitude RequestManager.getInstance().doFriendRequest().createWallPost( new NewsFeedPost(0, Long.valueOf(facebookUID), 1, System.currentTimeMillis() / 1000), null); } else { Log.v(TAG, "Login failed"); } } }
From source file:com.he5ed.lib.cloudprovider.auth.OAuth2Fragment.java
/** * Create a new user account or update the current user account * * @param user user information returned from server *//*from w w w .j ava2 s. c om*/ private void addAccount(User user) { boolean accountExist = false; AccountManager am = AccountManager.get(getActivity()); // check if account already exist in AccountManager Account[] accounts = am.getAccountsByType(CloudProvider.ACCOUNT_TYPE); for (Account account : accounts) { if (account.name.equals(user.id)) { accountExist = true; break; } } Account account = new Account(user.id, CloudProvider.ACCOUNT_TYPE); Bundle userData = new Bundle(); // must be string value String accessToken = mTokenInfo.get(Authenticator.KEY_ACCESS_TOKEN); String refreshToken = mTokenInfo.get(Authenticator.KEY_REFRESH_TOKEN); String expiryDuration = mTokenInfo.get(Authenticator.KEY_EXPIRY); if (accountExist) { // update current account access token am.setAuthToken(account, CloudProvider.AUTH_TYPE, accessToken); if (refreshToken != null) am.setUserData(account, Authenticator.KEY_REFRESH_TOKEN, refreshToken); if (expiryDuration != null) am.setUserData(account, Authenticator.KEY_EXPIRY, expiryDuration); } else { // add new account into AccountManager if (refreshToken != null) userData.putString(Authenticator.KEY_REFRESH_TOKEN, refreshToken); if (expiryDuration != null) userData.putString(Authenticator.KEY_EXPIRY, expiryDuration); userData.putString(Authenticator.KEY_CLOUD_API, AuthHelper.getCloudApi(mCloudApi)); userData.putString(Authenticator.KEY_USERNAME, user.name); userData.putString(Authenticator.KEY_EMAIL, user.email); userData.putString(Authenticator.KEY_AVATAR_URL, user.avatarUrl); am.addAccountExplicitly(account, null, userData); am.setAuthToken(account, CloudProvider.AUTH_TYPE, accessToken); } // send result back to AccountManager Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, user.id); result.putString(AccountManager.KEY_ACCOUNT_TYPE, CloudProvider.ACCOUNT_TYPE); ((AccountAuthenticatorActivity) getActivity()).setAccountAuthenticatorResult(result); getActivity().finish(); }
From source file:org.amahi.anywhere.activity.AuthenticationActivity.java
private void finishAuthentication(String authenticationToken) { AccountManager accountManager = AccountManager.get(this); Bundle authenticationBundle = new Bundle(); Account account = new AmahiAccount(getUsername()); if (accountManager.addAccountExplicitly(account, getPassword(), null)) { authenticationBundle.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); authenticationBundle.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); authenticationBundle.putString(AccountManager.KEY_AUTHTOKEN, authenticationToken); accountManager.setAuthToken(account, account.type, authenticationToken); }//from www. j av a2s . c o m setAccountAuthenticatorResult(authenticationBundle); setResult(Activity.RESULT_OK); finish(); }
From source file:com.google.sample.beaconservice.MainActivityFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == Constants.REQUEST_CODE_PICK_ACCOUNT) { // Receiving a result from the AccountPicker if (resultCode == Activity.RESULT_OK) { String name = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); accountNameView.setText(name); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("accountName", name); editor.apply();/* w w w. j a va2s . c om*/ } else if (resultCode == Activity.RESULT_CANCELED) { // The account picker dialog closed without selecting an account. // Notify users that they must pick an account to proceed. Toast.makeText(getActivity(), "Please pick an account", Toast.LENGTH_SHORT).show(); } } else if (requestCode == Constants.REQUEST_CODE_ENABLE_BLE) { if (resultCode == Activity.RESULT_OK) { createScanner(); } else if (resultCode == Activity.RESULT_CANCELED) { Toast.makeText(getActivity(), "Please enable Bluetooth", Toast.LENGTH_SHORT).show(); } } }
From source file:com.dogar.geodesic.activities.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_CANCELED) { this.finish(); }//from ww w . ja v a 2 s . c o m switch (requestCode) { case REQUEST_ACCOUNT_PICKER: if (data != null && data.getExtras() != null) { String accountName = data.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME); if (accountName != null) { saveLogin(this, accountName); headerResult.setActiveProfile(getSavedProfile()); } } break; } }
From source file:com.dogar.geodesic.map.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_CANCELED) this.finish(); switch (requestCode) { case REQUEST_ACCOUNT_PICKER: if (data != null && data.getExtras() != null) { String accountName = data.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME); if (accountName != null) { SharedPreferences.Editor editor = settings.edit(); editor.putString("ACCOUNT_NAME", accountName); editor.commit();/*from w w w . j a va 2 s .c om*/ setAccountName(accountName); if (mAdapter != null) { mAdapter.setHeaderTitle(accountName, 0); mAdapter.notifyDataSetChanged(); mDrawerList.setAdapter(mAdapter); } ContentResolver.setIsSyncable(credential.getSelectedAccount(), AUTHORITY, 1); setGMFragment(); } } break; } }