本文整理汇总了Java中android.accounts.AccountManager.getAccountsByType方法的典型用法代码示例。如果您正苦于以下问题:Java AccountManager.getAccountsByType方法的具体用法?Java AccountManager.getAccountsByType怎么用?Java AccountManager.getAccountsByType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.accounts.AccountManager
的用法示例。
在下文中一共展示了AccountManager.getAccountsByType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeSyncAccount
import android.accounts.AccountManager; //导入方法依赖的package包/类
public void initializeSyncAccount(Context context, ContentResolver contentResolver) {
initializeContactManager(context, contentResolver);
AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
Account[] accounts = accountManager.getAccountsByType(context.getPackageName());
if (accounts != null && accounts.length == 0) {
Account newAccount = new Account(context.getString(R.string.sync_account_name), context.getPackageName());
try {
accountManager.addAccountExplicitly(newAccount, null, null);
} catch (Exception e) {
Log.e(e);
}
}
initializeContactManager(context, contentResolver);
}
示例2: getUsername
import android.accounts.AccountManager; //导入方法依赖的package包/类
public static String getUsername(Context c) {
AccountManager manager = AccountManager.get(c);
Account[] accounts = manager.getAccountsByType("com.google");
List<String> possibleEmails = new LinkedList<String>();
for (Account account : accounts) {
// TODO: Check possibleEmail against an email regex or treat
// account.name as an email address only for certain account.type values.
possibleEmails.add(account.name);
}
if (!possibleEmails.isEmpty() && possibleEmails.get(0) != null) {
String email = possibleEmails.get(0);
String[] parts = email.split("@");
if (parts.length > 1)
return parts[0];
}
return null;
}
示例3: current
import android.accounts.AccountManager; //导入方法依赖的package包/类
public static OUser current(Context context) {
AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
Account[] accounts = accountManager.getAccountsByType(context.getString(R.string.auth_type));
if (accounts.length > 0) {
OUser user = new OUser();
user.fillFromAccount(accountManager, accounts[0]);
user.setAccount(accounts[0]);
return user;
}
return null;
}
示例4: setSyncActivated
import android.accounts.AccountManager; //导入方法依赖的package包/类
public void setSyncActivated(boolean enabled) {
ContentResolver.setMasterSyncAutomatically(enabled);
if (enabled) {
SyncAdapterType[] types = ContentResolver.getSyncAdapterTypes();
AccountManager accmgr = AccountManager.get(mContext);
for (SyncAdapterType type : types) {
Account[] accounts = accmgr.getAccountsByType(type.accountType);
for (Account account : accounts) {
if (Constants.DEBUG) {
Log.d(TAG, "synching account, name:" + account.name + ", type: " + account.type);
}
enabled = ContentResolver.getSyncAutomatically(account, type.authority);
if (enabled) {
// trigger update for next account
ContentResolver.requestSync(account, type.authority, new Bundle());
}
}
}
}
}
示例5: deleteAllAppAccounts
import android.accounts.AccountManager; //导入方法依赖的package包/类
public void deleteAllAppAccounts() {
try {
AccountManager am = AccountManager.get(ApplicationLoader.applicationContext);
Account[] accounts = am.getAccountsByType("org.telegram.messenger");
for (int a = 0; a < accounts.length; a++) {
am.removeAccount(accounts[a], null, null);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: populateAccountTextView
import android.accounts.AccountManager; //导入方法依赖的package包/类
private void populateAccountTextView() {
AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccountsByType(ACCOUNT_TYPE);
String accountString = "Accounts of type " + ACCOUNT_TYPE + " are : \n";
if (accounts.length != 0) {
for (Account account : accounts) {
accountString += "Account:" + account.name + "\n";
}
} else {
accountString = "No Accounts of type " + ACCOUNT_TYPE +
" found. Please add accounts before exporting.";
mAccountTextView.setTextColor(Color.RED);
}
mAccountTextView.setText(accountString);
}
示例7: sync
import android.accounts.AccountManager; //导入方法依赖的package包/类
public void sync(Bundle data) {
AccountManager manager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
Account[] accounts = manager.getAccountsByType(context.getString(R.string.auth_type));
if (accounts.length > 0) {
Bundle settings = new Bundle();
settings.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
settings.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
settings.putString(SyncAdapter.KEY_SYNC_MODEL, model.getModelName());
if (data != null)
settings.putAll(data);
ContentResolver.requestSync(accounts[0], model.getAuthority(), settings);
}
}
示例8: getOrCreateAccount
import android.accounts.AccountManager; //导入方法依赖的package包/类
private static Optional<AccountHolder> getOrCreateAccount(Context context) {
AccountManager accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccountsByType("im.cable.cableim");
Optional<AccountHolder> account;
if (accounts.length == 0) account = createAccount(context);
else account = Optional.of(new AccountHolder(accounts[0], false));
if (account.isPresent() && !ContentResolver.getSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY)) {
ContentResolver.setSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY, true);
}
return account;
}
示例9: restoreUIFromPref
import android.accounts.AccountManager; //导入方法依赖的package包/类
protected void restoreUIFromPref() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
lastSyncLocalTimestamp=MyPreferences.getFlowzrLastSync(getApplicationContext());
preferences.getLong(FlowzrSyncOptions.PROPERTY_LAST_SYNC_TIMESTAMP,0);
AccountManager accountManager = AccountManager.get(getApplicationContext());
Account[] accounts = accountManager.getAccountsByType("com.google");
for (Account account : accounts) {
if (preferences.getString(FlowzrSyncOptions.PROPERTY_USE_CREDENTIAL, "").equals(account.name)) {
useCredential = account;
}
}
TextView tv = (TextView) findViewById(R.id.sync_was);
tv.setText(getString(R.string.flowzr_sync_was) + " " + new Date(lastSyncLocalTimestamp).toLocaleString());
}
示例10: work
import android.accounts.AccountManager; //导入方法依赖的package包/类
protected Object work(Context context, DatabaseAdapter dba, String... params) throws ImportExportException {
AccountManager accountManager = AccountManager.get(context);
android.accounts.Account[] accounts = accountManager.getAccountsByType("com.google");
String accountName=MyPreferences.getFlowzrAccount(context);
if (accountName == null) {
NotificationManager nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context,
FlowzrSyncActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Builder mNotifyBuilder = new NotificationCompat.Builder(context);
mNotifyBuilder
.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.icon)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle(context.getString(R.string.flowzr_sync))
.setContentText(
context.getString(R.string.flowzr_choose_account));
nm.notify(0, mNotifyBuilder.build());
Log.i("Financisto","account name is null");
throw new ImportExportException(R.string.flowzr_choose_account);
}
Account useCredential = null;
for (int i = 0; i < accounts.length; i++) {
if (accountName.equals(((android.accounts.Account) accounts[i]).name)) {
useCredential=accounts[i];
}
}
accountManager.getAuthToken(useCredential, "ah", false, new GetAuthTokenCallback(), null);
return null;
}
示例11: getMailByAccountManager
import android.accounts.AccountManager; //导入方法依赖的package包/类
public static String getMailByAccountManager(Context context) {
AccountManager accManager = AccountManager.get(context);
Pattern gmailPattern = Patterns.EMAIL_ADDRESS;
Account acc[] = accManager.getAccountsByType("com.google");
for (Account account : acc) {
if (gmailPattern.matcher(account.name).matches()) {
return account.name;
}
}
WebtrekkLogging.log("could not get valid Account Email, check Permissions. Account:"+ Arrays.toString(accManager.getAccounts()));
return "";
}
示例12: createSyncAccount
import android.accounts.AccountManager; //导入方法依赖的package包/类
private Account createSyncAccount() {
AccountManager am = AccountManager.get(this);
Account[] accounts;
try {
accounts = am.getAccountsByType("de.slg.leoapp");
} catch (SecurityException e) {
accounts = new Account[0];
}
if (accounts.length > 0) {
return accounts[0];
}
Account newAccount = new Account("default_account", "de.slg.leoapp");
if (am.addAccountExplicitly(newAccount, "pass1", null)) {
ContentResolver.setIsSyncable(newAccount, "de.slg.leoapp", 1);
ContentResolver.setSyncAutomatically(newAccount, "de.slg.leoapp", true);
} else {
newAccount = null;
}
return newAccount;
}
示例13: signInOrCreateAnAccount
import android.accounts.AccountManager; //导入方法依赖的package包/类
private void signInOrCreateAnAccount() {
//Get list of accounts on device.
AccountManager am = AccountManager.get(BaseActivity.this);
Account[] accountArray = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
if (accountArray.length == 0) {
//Send the user to the "Add Account" page.
Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
intent.putExtra(Settings.EXTRA_ACCOUNT_TYPES,
new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE});
startActivity(intent);
} else {
//Try to log the user in with the first account on the device.
startLoginProcess();
mDrawerLayout.closeDrawer(GravityCompat.START);
}
}
示例14: getAccount
import android.accounts.AccountManager; //导入方法依赖的package包/类
private static Account getAccount(Context context) {
AccountManager accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccountsByType(SyncUtils.ACCOUNT_TYPE);
Account account;
if (accounts.length > 0) {
account = accounts[0];
} else {
account = null;
}
return account;
}
示例15: getOrCreateAccount
import android.accounts.AccountManager; //导入方法依赖的package包/类
private static Optional<AccountHolder> getOrCreateAccount(Context context) {
AccountManager accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccountsByType("id.kita.pesan.secure");
Optional<AccountHolder> account;
if (accounts.length == 0) account = createAccount(context);
else account = Optional.of(new AccountHolder(accounts[0], false));
if (account.isPresent() && !ContentResolver.getSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY)) {
ContentResolver.setSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY, true);
}
return account;
}