Search in sources :

Example 1 with AccountManager

use of android.accounts.AccountManager in project Signal-Android by WhisperSystems.

the class DirectoryHelper method createAccount.

private static Optional<AccountHolder> createAccount(Context context) {
    AccountManager accountManager = AccountManager.get(context);
    Account account = new Account(context.getString(R.string.app_name), "org.thoughtcrime.securesms");
    if (accountManager.addAccountExplicitly(account, null, null)) {
        Log.w(TAG, "Created new account...");
        ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
        return Optional.of(new AccountHolder(account, true));
    } else {
        Log.w(TAG, "Failed to create account!");
        return Optional.absent();
    }
}
Also used : Account(android.accounts.Account) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) AccountManager(android.accounts.AccountManager)

Example 2 with AccountManager

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

Example 3 with AccountManager

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

Example 4 with AccountManager

use of android.accounts.AccountManager in project android_frameworks_base by ParanoidAndroid.

the class AppLaunch method checkAccountSignIn.

private void checkAccountSignIn() {
    // for Gmail
    if (mRequiredAccounts == null || mRequiredAccounts.isEmpty()) {
        return;
    }
    final AccountManager am = (AccountManager) getInstrumentation().getTargetContext().getSystemService(Context.ACCOUNT_SERVICE);
    Account[] accounts = am.getAccounts();
    // use set here in case device has multiple accounts of the same type
    Set<String> foundAccounts = new HashSet<String>();
    for (Account account : accounts) {
        if (mRequiredAccounts.contains(account.type)) {
            foundAccounts.add(account.type);
        }
    }
    // are missing
    if (mRequiredAccounts.size() != foundAccounts.size()) {
        mRequiredAccounts.removeAll(foundAccounts);
        StringBuilder sb = new StringBuilder("Device missing these accounts:");
        for (String account : mRequiredAccounts) {
            sb.append(' ');
            sb.append(account);
        }
        fail(sb.toString());
    }
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) HashSet(java.util.HashSet)

Example 5 with AccountManager

use of android.accounts.AccountManager in project android_frameworks_base by ParanoidAndroid.

the class BugreportReceiver method findSendToAccount.

/**
     * Find the best matching {@link Account} based on build properties.
     */
private static Account findSendToAccount(Context context) {
    final AccountManager am = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    String preferredDomain = SystemProperties.get("sendbug.preferred.domain");
    if (!preferredDomain.startsWith("@")) {
        preferredDomain = "@" + preferredDomain;
    }
    final Account[] accounts = am.getAccounts();
    Account foundAccount = null;
    for (Account account : accounts) {
        if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
            if (!preferredDomain.isEmpty()) {
                // looking
                if (account.name.endsWith(preferredDomain)) {
                    return account;
                } else {
                    foundAccount = account;
                }
            // if we don't have a preferred domain, just return since it looks like
            // an email address
            } else {
                return account;
            }
        }
    }
    return foundAccount;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Aggregations

AccountManager (android.accounts.AccountManager)180 Account (android.accounts.Account)121 Bundle (android.os.Bundle)28 Intent (android.content.Intent)18 PackageManager (android.content.pm.PackageManager)16 View (android.view.View)16 TextView (android.widget.TextView)16 Context (android.content.Context)15 IOException (java.io.IOException)14 UserAccountManager (com.nextcloud.client.account.UserAccountManager)13 OperationCanceledException (android.accounts.OperationCanceledException)11 ImageView (android.widget.ImageView)9 AuthenticatorDescription (android.accounts.AuthenticatorDescription)8 UserHandle (android.os.UserHandle)8 LayoutInflater (android.view.LayoutInflater)8 AuthenticatorException (android.accounts.AuthenticatorException)7 UserInfo (android.content.pm.UserInfo)7 Resources (android.content.res.Resources)7 Drawable (android.graphics.drawable.Drawable)7 LinearLayout (android.widget.LinearLayout)7