List of usage examples for android.accounts AccountManager get
public static AccountManager get(Context context)
From source file:com.einzig.ipst2.activities.MainActivity.java
/** * Search through accounts on the user's device now that we have permission to do so. *//*from w ww. j a v a 2s.c o m*/ public void gotAccountsPermission() { AccountManager manager = AccountManager.get(MainActivity.this); int numGoogAcct = 0; Account[] accountList = manager.getAccounts(); for (Account a : accountList) { if (a.type.equals("com.google")) { numGoogAcct++; } } if (numGoogAcct == 0) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this, ThemeHelper.getDialogTheme(this)); builder.setTitle(R.string.noaccountstitle); builder.setMessage(R.string.noaccountsmessage);//. Would you like to log in manually?") builder.setCancelable(true); builder.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.show(); } else { runOnUiThread(new Runnable() { @Override public void run() { findViewById(R.id.progress_view_mainactivity).setVisibility(View.VISIBLE); findViewById(R.id.gmail_login_button).setVisibility(View.INVISIBLE); } }); Intent intent = AccountManager.newChooseAccountIntent(null, null, new String[] { "com.google" }, false, null, null, null, null); startActivityForResult(intent, LOGIN_ACTIVITY_CODE); } }
From source file:com.github.pockethub.android.ui.MainActivity.java
@VisibleForTesting
AccountManager getAccountManager() {
return AccountManager.get(this);
}
From source file:com.cyanogenmod.account.ui.SetupWizardActivity.java
private boolean accountExists(String accountType) { return AccountManager.get(this).getAccountsByType(accountType).length > 0; }
From source file:edu.mit.mobile.android.locast.net.NetworkClient.java
protected synchronized void loadFromExistingAccount(Account account) { if (account == null) { throw new IllegalArgumentException("must specify account"); }/* ww w .j a v a 2 s . c o m*/ String baseUrlString; final AccountManager am = AccountManager.get(mContext); baseUrlString = am.getUserData(account, AuthenticationService.USERDATA_LOCAST_API_URL); if (baseUrlString == null) { Log.w(TAG, "loading base URL from preferences instead of account metadata"); baseUrlString = getBaseUrlFromPreferences(mContext); // if it's null in the userdata, then it must be an account from before this feature // was added. // Store for later use. am.setUserData(account, AuthenticationService.USERDATA_LOCAST_API_URL, baseUrlString); } try { setBaseUrl(baseUrlString); setCredentialsFromAccount(account); } catch (final MalformedURLException e) { Log.e(TAG, e.getLocalizedMessage(), e); } }
From source file:com.murrayc.galaxyzoo.app.LoginUtils.java
/** * Get the Account.//from ww w . j av a 2 s.co m * * Don't call this from the main thread - use an AsyncTask, for instance. * * @param context * @return */ private static Account getAccount(final Context context) { final AccountManager mgr = AccountManager.get(context); return getAccount(mgr); }
From source file:com.xiaomi.account.utils.SysHelper.java
public static HashMap<String, String> querySnsInfoFromServer(Context context, Account account) { if (account == null) { Log.w(TAG, "no Xiaomi account, skip to querySnsInfoFromServer"); return null; }// www .j a va 2 s. c om String userId = account.name; AccountManager am = AccountManager.get(context); int count = 0; while (count < 2) { String authToken = getAuthToken(am, account, Constants.PASSPORT_API_SID); ExtendedAuthToken extendedAuthToken = ExtendedAuthToken.parse(authToken); if (extendedAuthToken != null) { String serviceToken = extendedAuthToken.authToken; String security = extendedAuthToken.security; if (serviceToken == null || security == null) { break; } String encryptedUserId = am.getUserData(account, Constants.KEY_ENCRYPTED_USER_ID); try { HashMap<String, String> data = Maps.newHashMap(); data.put(com.xiaomi.account.Constants.EXTRA_SINA_WEIBO_ACCESSTOKEN, CloudHelper.getBindedAccessToken(userId, encryptedUserId, com.xiaomi.account.Constants.SINA_WEIBO_SNS_TYPE, serviceToken, security)); data.put(com.xiaomi.account.Constants.EXTRA_QQ_ACCESSTOKEN, CloudHelper.getBindedAccessToken(userId, encryptedUserId, com.xiaomi.account.Constants.QQ_SNS_TYPE, serviceToken, security)); if (!Build.IS_INTERNATIONAL_BUILD) { return data; } data.put(com.xiaomi.account.Constants.EXTRA_FACEBOOK_ACCESSTOKEN, CloudHelper.getBindedAccessToken(userId, encryptedUserId, com.xiaomi.account.Constants.FACEBOOK_SNS_TYPE, serviceToken, security)); return data; } catch (InvalidResponseException e) { Log.e(TAG, "invalid response when get user info", e); } catch (CipherException e2) { Log.e(TAG, "CipherException when get user info", e2); } catch (IOException e3) { Log.e(TAG, "IOException when get user info", e3); } catch (AuthenticationFailureException e4) { Log.e(TAG, "auth failure when get user info", e4); am.invalidateAuthToken(account.type, authToken); count++; } catch (AccessDeniedException e5) { Log.e(TAG, "access denied when get user info", e5); } } else { break; } } return null; }
From source file:com.murrayc.galaxyzoo.app.LoginUtils.java
static void copyPrefToAccount(final Context context, final String key, final String value) { //Copy the preference to the Account: final AccountManager mgr = AccountManager.get(context); final Account account = getAccount(context); if (account == null) { return;//from w ww . j a va2 s . c om } copyPrefToAccount(mgr, account, key, value); }
From source file:com.owncloud.android.ui.activity.DrawerActivity.java
/** * updates the account list in the drawer. *///from www . ja v a 2s .c o m private void updateAccountList() { Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType()); if (mNavigationView != null && mDrawerLayout != null) { if (accounts.length > 0) { repopulateAccountList(accounts); setAccountInDrawer(AccountUtils.getCurrentOwnCloudAccount(this)); populateDrawerOwnCloudAccounts(); // activate second/end account avatar if (mAccountsWithAvatars[1] != null) { DisplayUtils.showAccountAvatar(mAccountsWithAvatars[1], (ImageView) findNavigationViewChildById(R.id.drawer_account_end), mOtherAccountAvatarRadiusDimension, false); mAccountEndAccountAvatar.setVisibility(View.VISIBLE); } else { mAccountEndAccountAvatar.setVisibility(View.GONE); } // activate third/middle account avatar if (mAccountsWithAvatars[2] != null) { DisplayUtils.showAccountAvatar(mAccountsWithAvatars[2], (ImageView) findNavigationViewChildById(R.id.drawer_account_middle), mOtherAccountAvatarRadiusDimension, false); mAccountMiddleAccountAvatar.setVisibility(View.VISIBLE); } else { mAccountMiddleAccountAvatar.setVisibility(View.GONE); } } else { mAccountEndAccountAvatar.setVisibility(View.GONE); mAccountMiddleAccountAvatar.setVisibility(View.GONE); } } }
From source file:es.uma.lcc.tasks.DecryptionRequestTask.java
private void handleAuthenticationError() { System.out.println("retrying"); mIsFirstRun = false;//from w w w.j a v a 2s . c o m Thread t = new CookieRefresherThread(AccountManager.get(mMainActivity), mMainActivity); t.start(); try { t.join(); (new DecryptionRequestTask(mPicId, mSrc, mMainActivity, false)).execute(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:com.capstonecontrol.AccountsActivity.java
/** * Returns a list of registered Google account names. If no Google accounts * are registered on the device, a zero-length list is returned. *///from ww w .j av a2 s . c o m private List<String> getGoogleAccounts() { ArrayList<String> result = new ArrayList<String>(); Account[] accounts = AccountManager.get(mContext).getAccounts(); for (Account account : accounts) { if (account.type.equals("com.google")) { result.add(account.name); } } return result; }