Search in sources :

Example 76 with AccountManager

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);
            }
        }
    }
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) AccountListAdapter(com.owncloud.android.ui.adapter.AccountListAdapter)

Example 77 with AccountManager

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());
}
Also used : AccountManagerCallback(android.accounts.AccountManagerCallback) Activity(android.app.Activity) Handler(android.os.Handler) AccountManager(android.accounts.AccountManager)

Example 78 with AccountManager

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;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 79 with AccountManager

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;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 80 with AccountManager

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);
    }
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Aggregations

AccountManager (android.accounts.AccountManager)105 Account (android.accounts.Account)76 Bundle (android.os.Bundle)14 IOException (java.io.IOException)11 Intent (android.content.Intent)10 OperationCanceledException (android.accounts.OperationCanceledException)7 AuthenticatorException (android.accounts.AuthenticatorException)5 View (android.view.View)5 TextView (android.widget.TextView)5 HashSet (java.util.HashSet)5 SharedPreferences (android.content.SharedPreferences)4 AccountManagerCallback (android.accounts.AccountManagerCallback)3 Paint (android.graphics.Paint)3 JSONException (org.json.JSONException)3 AccountsException (android.accounts.AccountsException)2 TargetApi (android.annotation.TargetApi)2 AlertDialog (android.app.AlertDialog)2 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 OperationApplicationException (android.content.OperationApplicationException)2