Search code examples
androidsynchronizationandroid-contentresolveraccounts

List supported authorites for selected accounts


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?


Solution

  • 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.