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();
}
}
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);
}
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;
}
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());
}
}
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;
}
Aggregations