0

How to get application account that I create? In my SyncAdapter I have account in onPerformSync method, but how I can get the account outside SyncAdapter without adding GET_ACCOUNTS permission, for ex. in MainActivity?

The target is that I want to handle Sync options from my application, like checking is sync is enable etc.

Miquel Coll
  • 759
  • 15
  • 49
miecio
  • 315
  • 1
  • 4
  • 19

1 Answers1

0

You will need the GET_ACCOUNTS permission to do whatever you are trying to do. You can get the application account you create by doing something like this:

public static Account[] getAccounts(Context context) {
    AccountManager accManager = AccountManager.get(context);
    return accManager.getAccountsByType(ACCOUNT_TYPE);
}

Here the ACCOUNT_TYPE refers to the type of your account that you create. This will get you back a list of the accounts, if you have multiple ones.

What do you mean by "handle sync options"?

But you can use the various static methods of the ContentResolver class to get/set the various attributes for a sync adapter. For example, to check if sync is enabled for your account you can use:

Bhuvan
  • 285
  • 1
  • 3
  • 11