Reputation: 6683
I have pragmatically started i sync Google calender evens using following code. But how we know sync is completed or failed
private void requestCalendarSync()
{
AccountManager aM = AccountManager.get(this);
Account[] accounts = aM.getAccounts();
for (Account account : accounts)
{
int isSyncable = ContentResolver.getIsSyncable(account, CalendarContract.AUTHORITY);
if (isSyncable > 0)
{
Bundle extras = new Bundle();
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
ContentResolver.requestSync(accounts[0], CalendarContract.AUTHORITY, extras);
}
}
}
Upvotes: 0
Views: 89
Reputation: 5020
I think you should use SyncStatusObserver to get notifications about sync status changes.
Register your observer with the following method:
ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE, new MySyncStatusObserver());
Implement the onStatusChanged method:
private class MySyncStatusObserver implements SyncStatusObserver {
@Override
public void onStatusChanged(int which) {
if (ContentResolver.isSyncActive(mAccount, CalendarContract.AUTHORITY)) {
// There is now an active sync.
} else {
// There is no longer an active sync.
}
}
};
Upvotes: 1