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
?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With