Created
January 15, 2015 11:47
-
-
Save sebastienrouif/d34f7f094b5d7ca0f6ae to your computer and use it in GitHub Desktop.
SyncAdapter status listener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private SyncStatusObserver mSyncStatusObserver = new SyncStatusObserver() { | |
@Override | |
public void onStatusChanged(int which) { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
String accountName = AccountUtils.getActiveAccountName(BaseActivity.this); | |
if (TextUtils.isEmpty(accountName)) { | |
onRefreshingStateChanged(false); | |
mManualSyncRequest = false; | |
return; | |
} | |
Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE); | |
boolean syncActive = ContentResolver.isSyncActive( | |
account, ScheduleContract.CONTENT_AUTHORITY); | |
boolean syncPending = ContentResolver.isSyncPending( | |
account, ScheduleContract.CONTENT_AUTHORITY); | |
if (!syncActive && !syncPending) { | |
mManualSyncRequest = false; | |
} | |
onRefreshingStateChanged(syncActive || (mManualSyncRequest && syncPending)); | |
} | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment