List of usage examples for android.accounts AccountManager getAccountsByType
@NonNull
public Account[] getAccountsByType(String type)
From source file:Main.java
public static Account[] GetAccounts(AccountManager accountManager) { return accountManager.getAccountsByType("com.google"); }
From source file:Main.java
private static Account getAccount(AccountManager accountManager) { Account[] accounts = accountManager.getAccountsByType("com.google"); Account account = null;// w w w. j a v a2s. c o m if (accounts.length > 0) { account = accounts[0]; } return account; }
From source file:Main.java
private static Account getAccount(AccountManager accountManager) { Account[] accounts = accountManager.getAccountsByType("com.google"); Account account;//w w w .j a v a 2 s. c o m if (accounts.length > 0) { account = accounts[0]; } else { account = null; } return account; }
From source file:Main.java
public static boolean isAccountExists(Context context) { AccountManager manager = AccountManager.get(context); Account[] accounts = manager.getAccountsByType(ACCOUNT_TYPE); return accounts.length > 0; }
From source file:Main.java
public static Account findGoogleAccount(Context context, String name) { AccountManager am = AccountManager.get(context); for (final Account a : am.getAccountsByType(GOOGLE_TYPE)) { if (TextUtils.equals(a.name, name)) return a; }// ww w.j a v a2s .c om return null; }
From source file:Main.java
public static List<Account> getAccounts(final Context context) { AccountManager accountManager = AccountManager.get(context); return Arrays.asList(accountManager.getAccountsByType(GOOGLE_ACCOUNT_TYPE)); }
From source file:Main.java
public static Account getAccount(final Context context, final String accountName) { final AccountManager manager = AccountManager.get(context); Account[] accounts = manager.getAccountsByType(GOOGLE_ACCOUNT_TYPE); for (Account account : accounts) { if (account.name.equals(accountName)) { return account; }// w ww . j ava 2 s. c o m } return null; }
From source file:Main.java
public static Account getAccount(Context context, String accountName) { AccountManager accountManager = AccountManager.get(context); Account[] accounts = accountManager.getAccountsByType(ACCOUNT_TYPE); for (Account account : accounts) { if (account.name.equalsIgnoreCase(accountName)) { return account; }//from ww w .j a v a 2 s . co m } return null; }
From source file:Main.java
public static String getPrimaryAccountEmail(Context context) { AccountManager accountManager = AccountManager.get(context); Account[] accounts = accountManager.getAccountsByType("com.google"); if (accounts == null || accounts.length == 0) { Log.w(LOG_PREFIX, "Could not find name of primary google account. Returning null"); return null; } else {/*from w w w . jav a 2s.c om*/ String name = accounts[0].name; Log.d(LOG_PREFIX, "Found " + accounts.length + " google accounts. Returning name:" + name); return name; } }
From source file:Main.java
public static String getUserEmailOnDevice(Context ctx) { AccountManager manager = AccountManager.get(ctx); 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); }//from w w w .j a v a2s . c om if (!possibleEmails.isEmpty() && possibleEmails.get(0) != null) { String email = possibleEmails.get(0); String[] parts = email.split("@"); if (parts.length > 0 && parts[0] != null) return email; else return null; } else return null; }