use of android.accounts.Account in project Reader by TheKeeperOfPie.
the class ControllerUser method setAccount.
public void setAccount(Account accountUser) {
boolean accountFound = false;
Account[] accounts = accountManager.getAccountsByType(Reddit.ACCOUNT_TYPE);
for (Account account : accounts) {
if (account.name.equals(accountUser.name)) {
this.account = account;
accountFound = true;
reloadUser();
break;
}
}
user = new User();
if (!accountFound) {
account = null;
} else {
user.setName(account.name);
}
}
use of android.accounts.Account in project SeriesGuide by UweTrottmann.
the class TraktCredentials method getAccessToken.
/**
* Get the access token. Avoid keeping this in memory, maybe calling {@link #hasCredentials()}
* is sufficient.
*/
public String getAccessToken() {
Account account = AccountUtils.getAccount(mContext);
if (account == null) {
return null;
}
AccountManager manager = AccountManager.get(mContext);
return manager.getPassword(account);
}
use of android.accounts.Account in project SeriesGuide by UweTrottmann.
the class TraktCredentials method setAccessToken.
private boolean setAccessToken(String accessToken) {
Account account = AccountUtils.getAccount(mContext);
if (account == null) {
// try to create a new account
AccountUtils.createAccount(mContext);
}
account = AccountUtils.getAccount(mContext);
if (account == null) {
// give up
return false;
}
AccountManager manager = AccountManager.get(mContext);
manager.setPassword(account, accessToken);
return true;
}
use of android.accounts.Account in project SeriesGuide by UweTrottmann.
the class AccountUtils method removeAccount.
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
private static void removeAccount(Context context) {
Timber.d("Removing existing accounts...");
AccountManager manager = AccountManager.get(context);
Account[] accounts = manager.getAccountsByType(ACCOUNT_TYPE);
for (Account account : accounts) {
if (AndroidUtils.isLollipopMR1OrHigher()) {
manager.removeAccount(account, null, null, null);
} else {
//noinspection deprecation
manager.removeAccount(account, null, null);
}
}
Timber.d("Removing existing accounts...DONE");
}
use of android.accounts.Account in project SeriesGuide by UweTrottmann.
the class AccountUtils method createAccount.
public static void createAccount(Context context) {
Timber.d("Setting up account...");
// remove any existing accounts
removeAccount(context);
// try to create a new account
AccountManager manager = AccountManager.get(context);
Account account = new Account(ACCOUNT_NAME, ACCOUNT_TYPE);
boolean isNewAccountAdded;
try {
isNewAccountAdded = manager != null && manager.addAccountExplicitly(account, null, null);
} catch (SecurityException e) {
Timber.e(e, "Setting up account...FAILED Account could not be added");
return;
}
if (isNewAccountAdded) {
// Inform the system that this account supports sync
ContentResolver.setIsSyncable(account, SgApp.CONTENT_AUTHORITY, 1);
// Inform the system that this account is eligible for auto sync
// when the network is up
ContentResolver.setSyncAutomatically(account, SgApp.CONTENT_AUTHORITY, true);
// Recommend a schedule for automatic synchronization. The system
// may modify this based
// on other scheduled syncs and network utilization.
ContentResolver.addPeriodicSync(account, SgApp.CONTENT_AUTHORITY, new Bundle(), SYNC_FREQUENCY);
}
Timber.d("Setting up account...DONE");
}
Aggregations