+ public static boolean exists(Account account, Context context) {\r
+ Account[] ocAccounts = AccountManager.get(context).getAccountsByType(\r
+ MainApp.getAccountType());\r
+\r
+ if (account != null && account.name != null) {\r
+ int lastAtPos = account.name.lastIndexOf("@");\r
+ String hostAndPort = account.name.substring(lastAtPos + 1);\r
+ String username = account.name.substring(0, lastAtPos);\r
+ String otherHostAndPort, otherUsername;\r
+ Locale currentLocale = context.getResources().getConfiguration().locale;\r
+ for (Account otherAccount : ocAccounts) {\r
+ lastAtPos = otherAccount.name.lastIndexOf("@");\r
+ otherHostAndPort = otherAccount.name.substring(lastAtPos + 1);\r
+ otherUsername = otherAccount.name.substring(0, lastAtPos);\r
+ if (otherHostAndPort.equals(hostAndPort) &&\r
+ otherUsername.toLowerCase(currentLocale).\r
+ equals(username.toLowerCase(currentLocale))) {\r
+ return true;\r
+ }\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+ \r