List supported authorites for selected accounts
Asked Answered
C

1

9

I'm trying to develop an application which syncs only selected accounts using ContentResolver.requestSync(account, authority, extras);.

I was able to sync contacts and calendar by using com.android.contacts and com.android.calendar respectively as authority.

But, is there any way to get the list of authorities supported by a specific account?

Also, what is the effect of using null as authority?

Charlatanism answered 26/7, 2012 at 5:12 Comment(0)
G
4

Use getSyncAdapterTypes() to get information about the SyncAdapters that are known to the system.

SyncAdapterType[] types = ContentResolver.getSyncAdapterTypes();
for (SyncAdapterType type : types) {
    if (yourAccount.type.equals(type.accountType)) {
        boolean isSyncable = ContentResolver.getIsSyncable(yourAccount, type.authority) > 0;
        if (isSyncable) {
            ContentResolver.requestSync(yourAccount, type.authority, extras);
        }
    }
}

Don't forget getIsSyncable() method requires READ_SYNC_SETTINGS permission.

Groat answered 31/7, 2012 at 9:25 Comment(1)
Thankz @biegleux.. its working.. but, its not giving the authority to sync emails.. any idea??Charlatanism

© 2022 - 2024 — McMap. All rights reserved.