我已经实际开始使用以下代码同步Google日历平均值。但我们如何知道同步已完成或失败
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);
}
}
}
答案 0 :(得分:1)
我认为您应该使用SyncStatusObserver来获取有关同步状态更改的通知。
使用以下方法注册观察者:
ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE, new MySyncStatusObserver());
实施onStatusChanged方法:
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.
}
}
};