user1782267
user1782267

Reputation: 313

How to list out all the accounts (Facebook, Twitter, Gmail, etc) in Android?

I am planning to write a simple code which lists out all the accounts associated in my Android phone such as Facebook, Twitter, Gmail, Dropbox and so on...

    AccountManager am = AccountManager.get(this);
    Account [] acc = am.getAccounts();
    if (acc.length > 0){
        for (int i=0; i<acc.length; i++){
            listedAcc = acc[i] + "\n";
        }
        accounts.setText(listedAcc.toString());

After running the above coding, the TextView "accounts" only shows me

    Account {[email protected],
             type=com.android.exchange}

How I am going to do in order to list out all other accounts in my phone... Thanks...

Upvotes: 1

Views: 2522

Answers (1)

s.d
s.d

Reputation: 29436

Use a String and concatenate properly (+= instead of =):

AccountManager am = AccountManager.get(this);
Account [] acc = am.getAccounts();
if (acc.length > 0){
    String s = "";
    for (int i=0; i<acc.length; i++){
        s += acc[i] + "\n";
    }
    accounts.setText(s)

Upvotes: 6

Related Questions