use of android.accounts.AccountManager in project android by owncloud.
the class ManageAccountsActivity method run.
/**
* Callback executed after the {@link AccountManager} removed an account
*
* @param future Result of the removal; future.getResult() is true if account was removed correctly.
*/
@Override
public void run(AccountManagerFuture<Boolean> future) {
if (future != null && future.isDone()) {
Account account = new Account(mAccountBeingRemoved, MainApp.getAccountType());
if (!AccountUtils.exists(account, MainApp.getAppContext())) {
// Cancel transfers of the removed account
if (mUploaderBinder != null) {
mUploaderBinder.cancel(account);
}
if (mDownloaderBinder != null) {
mDownloaderBinder.cancel(account);
}
}
mAccountListAdapter = new AccountListAdapter(this, getAccountListItems(), mTintedCheck);
mListView.setAdapter(mAccountListAdapter);
AccountManager am = AccountManager.get(this);
if (am.getAccountsByType(MainApp.getAccountType()).length == 0) {
// Show create account screen if there isn't any account
am.addAccount(MainApp.getAccountType(), null, null, null, this, null, null);
} else {
// at least one account left
if (AccountUtils.getCurrentOwnCloudAccount(this) == null) {
// current account was removed - set another as current
String accountName = "";
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
if (accounts.length != 0) {
accountName = accounts[0].name;
}
AccountUtils.setCurrentOwnCloudAccount(this, accountName);
}
}
}
}
use of android.accounts.AccountManager in project android by owncloud.
the class RemoveAccountDialogFragment method onConfirmation.
/**
* Performs the removal of the target account.
*/
@Override
public void onConfirmation(String callerTag) {
Activity parentActivity = getActivity();
AccountManager am = AccountManager.get(parentActivity);
AccountManagerCallback<Boolean> callback = (AccountManagerCallback<Boolean>) parentActivity;
am.removeAccount(mTargetAccount, callback, new Handler());
}
use of android.accounts.AccountManager in project SeriesGuide by UweTrottmann.
the class AccountUtils method isAccountExists.
public static boolean isAccountExists(Context context) {
AccountManager manager = AccountManager.get(context);
Account[] accounts = manager.getAccountsByType(ACCOUNT_TYPE);
return accounts.length > 0;
}
use of android.accounts.AccountManager in project SeriesGuide by UweTrottmann.
the class AccountUtils method getAccount.
public static Account getAccount(Context context) {
AccountManager manager = AccountManager.get(context);
Account[] accounts = manager.getAccountsByType(ACCOUNT_TYPE);
// return first available account
if (accounts.length > 0) {
return accounts[0];
}
return null;
}
use of android.accounts.AccountManager in project jpHolo by teusink.
the class ContactAccessorSdk5 method save.
@Override
public /**
* This method will save a contact object into the devices contacts database.
*
* @param contact the contact to be saved.
* @returns the id if the contact is successfully saved, null otherwise.
*/
String save(JSONObject contact) {
AccountManager mgr = AccountManager.get(mApp.getActivity());
Account[] accounts = mgr.getAccounts();
String accountName = null;
String accountType = null;
if (accounts.length == 1) {
accountName = accounts[0].name;
accountType = accounts[0].type;
} else if (accounts.length > 1) {
for (Account a : accounts) {
if (a.type.contains("eas") && a.name.matches(EMAIL_REGEXP)) /*Exchange ActiveSync*/
{
accountName = a.name;
accountType = a.type;
break;
}
}
if (accountName == null) {
for (Account a : accounts) {
if (a.type.contains("com.google") && a.name.matches(EMAIL_REGEXP)) /*Google sync provider*/
{
accountName = a.name;
accountType = a.type;
break;
}
}
}
if (accountName == null) {
for (Account a : accounts) {
if (a.name.matches(EMAIL_REGEXP)) /*Last resort, just look for an email address...*/
{
accountName = a.name;
accountType = a.type;
break;
}
}
}
}
String id = getJsonString(contact, "id");
if (id == null) {
// Create new contact
return createNewContact(contact, accountType, accountName);
} else {
// Modify existing contact
return modifyContact(id, contact, accountType, accountName);
}
}
Aggregations