Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 439
JiTHiN Avatar asked Jul 26 '12 05:07

JiTHiN


1 Answers

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.

like image 115
biegleux Avatar answered Nov 20 '22 17:11

biegleux