Sometimes it is required to get all the accounts registered in device like facebook , gmail, linkedin account as well as whatsapp account.
Account Manager provides list of all centralized account of device.
First of all we can have the instance of account manager using get(Context) method.
then we can List the available accounts using getAccountType(String type) if anyone interested in account type otherwise use getAccounts().
AccountManager accoutnManager = AccountManager.get(this);
Account [] accounts = accoutnManager.getAccounts();
if (accounts.length > 0){
String totals = "";
for (int i=0; i<accounts.length; i++){
totals += accounts[i] + "\n";
}
accounts.setText(totals)
getAccounts() return the list of accounts, it's safe to call this from Main thread.
0 Comment(s)