use of android.accounts.AccountManager in project android-delicious by lexs.
the class DeliciousAccount method get.
public static DeliciousAccount get(Context context) {
AccountManager accountManager = AccountManager.get(context.getApplicationContext());
Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE);
if (accounts.length > 0) {
return new DeliciousAccount(context, accountManager, accounts[0]);
} else {
return null;
}
}
use of android.accounts.AccountManager in project iosched by google.
the class LoginUtils method setFirstAvailableAccountAsActive.
/**
*
* @return account name, or a test account name
*/
public static String setFirstAvailableAccountAsActive(Context context) {
String account;
AccountManager am = AccountManager.get(InstrumentationRegistry.getTargetContext());
Account[] accountArray = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
if (accountArray.length > 0) {
account = accountArray[0].name;
} else {
account = DUMMY_ACCOUNT_NAME;
}
AccountUtils.setActiveAccount(InstrumentationRegistry.getTargetContext(), account);
return account;
}
use of android.accounts.AccountManager in project iosched by google.
the class AndroidAuthenticator method getAuthToken.
// TODO: Figure out what to do about notifyAuthFailure
@SuppressWarnings("deprecation")
@Override
public String getAuthToken() throws AuthFailureError {
final AccountManager accountManager = AccountManager.get(mContext);
AccountManagerFuture<Bundle> future = accountManager.getAuthToken(mAccount, mAuthTokenType, mNotifyAuthFailure, null, null);
Bundle result;
try {
result = future.getResult();
} catch (Exception e) {
throw new AuthFailureError("Error while retrieving auth token", e);
}
String authToken = null;
if (future.isDone() && !future.isCancelled()) {
if (result.containsKey(AccountManager.KEY_INTENT)) {
Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
throw new AuthFailureError(intent);
}
authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
}
if (authToken == null) {
throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
}
return authToken;
}
use of android.accounts.AccountManager in project MWM-for-Android-Gen1 by MetaWatchOpenProjects.
the class Utils method getGoogleAccountName.
public static String getGoogleAccountName(Context context) {
AccountManager accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccounts();
int count = accounts.length;
Account account = null;
for (int i = 0; i < count; i++) {
account = accounts[i];
if (account.type.equals("com.google")) {
return account.name;
}
}
return "";
}
use of android.accounts.AccountManager in project Notes by MiCode.
the class GTaskClient method loginGoogleAccount.
private String loginGoogleAccount(Activity activity, boolean invalidateToken) {
String authToken;
AccountManager accountManager = AccountManager.get(activity);
Account[] accounts = accountManager.getAccountsByType("com.google");
if (accounts.length == 0) {
Log.e(TAG, "there is no available google account");
return null;
}
String accountName = NotesPreferenceActivity.getSyncAccountName(activity);
Account account = null;
for (Account a : accounts) {
if (a.name.equals(accountName)) {
account = a;
break;
}
}
if (account != null) {
mAccount = account;
} else {
Log.e(TAG, "unable to get an account with the same name in the settings");
return null;
}
// get the token now
AccountManagerFuture<Bundle> accountManagerFuture = accountManager.getAuthToken(account, "goanna_mobile", null, activity, null, null);
try {
Bundle authTokenBundle = accountManagerFuture.getResult();
authToken = authTokenBundle.getString(AccountManager.KEY_AUTHTOKEN);
if (invalidateToken) {
accountManager.invalidateAuthToken("com.google", authToken);
loginGoogleAccount(activity, false);
}
} catch (Exception e) {
Log.e(TAG, "get auth token failed");
authToken = null;
}
return authToken;
}
Aggregations