public SyncStatusManager(Context context, String authority) { mContext = context; mAuthority = authority; syncObserver = new SyncStatusObserver() { @Override public void onStatusChanged(final int which) { AccountManager accountManager = AccountManager.get(mContext); if (accountManager != null) { Account[] accounts = accountManager.getAccountsByType(AccountGeneral.ACCOUNT_TYPE); if (accounts.length > 0) { Account account = accounts[0]; int state = -1; if (which == ContentResolver.SYNC_OBSERVER_TYPE_PENDING) { // 'Pending' state changed. if (ContentResolver.isSyncPending(account, mAuthority)) { // There is now a pending sync. state = STATE_NOW_PENDING; } else { // There is no longer a pending sync. state = STATE_NO_LONGER_PENDING; } } else if (which == ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE) { // 'Active' state changed. if (ContentResolver.isSyncActive(account, mAuthority)) { // There is now an active sync. state = STATE_NOW_SYNCING; } else { // There is no longer an active sync. state = STATE_NO_LONGER_SYNCING; } } Log.d(MainActivity.TAG, "Notifying sync status: " + state); for (OnSyncStatusChangedListener listener : listeners) { listener.onStatusChanged(state, mAuthority); } } } } }; }
@Override public Object addStatusChangeListener(int mask, SyncStatusObserver callback) { return ContentResolver.addStatusChangeListener(mask, callback); }
Object addStatusChangeListener(int mask, SyncStatusObserver callback);