public static void configureSyncFor(Account account) { Log.d(TAG, "Configuring account sync"); ContentResolver.setIsSyncable(account, BuildConfig.PROVIDER_AUTHORITY_SYNC, 1); ContentResolver.setSyncAutomatically(account, BuildConfig.PROVIDER_AUTHORITY_SYNC, true); ContentResolver.addPeriodicSync(account, BuildConfig.PROVIDER_AUTHORITY_SYNC, new Bundle(), SYNC_PERIOD); }
@Test public void shouldSetSyncAutomatically() { assertThat(ContentResolver.getSyncAutomatically(a, AUTHORITY)).isFalse(); ContentResolver.setSyncAutomatically(a, AUTHORITY, true); assertThat(ContentResolver.getSyncAutomatically(a, AUTHORITY)).isTrue(); }
//Create Account mAccount = createSyncAccount(this); //Turn on periodic syncing ContentResolver resolver = getContentResolver(); resolver.setIsSyncable(mAccount, AUTHORITY, 1); resolver.setSyncAutomatically(mAccount, AUTHORITY, true); resolver.addPeriodicSync( mAccount, AUTHORITY, Bundle.EMPTY, 30);
public void setAutoSync(String authority, boolean autoSync) { try { Account account = mUser.getAccount(); if (!ContentResolver.isSyncActive(account, authority)) { ContentResolver.setSyncAutomatically(account, authority, autoSync); } } catch (NullPointerException e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); } }
@Override public void onDestroy() { super.onDestroy(); mHandler.removeCallbacks(mRunnable); ContentResolver.setSyncAutomatically(Aware.getAWAREAccount(this), Processor_Provider.getAuthority(this), false); ContentResolver.removePeriodicSync( Aware.getAWAREAccount(this), Processor_Provider.getAuthority(this), Bundle.EMPTY ); if (Aware.DEBUG) Log.d(TAG, "Processor service terminated..."); }
@Override public void onDestroy() { super.onDestroy(); sensorHandler.removeCallbacksAndMessages(null); mSensorManager.unregisterListener(this, mMagnetometer); sensorThread.quit(); wakeLock.release(); unregisterReceiver(dataLabeler); ContentResolver.setSyncAutomatically(Aware.getAWAREAccount(this), Magnetometer_Provider.getAuthority(this), false); ContentResolver.removePeriodicSync( Aware.getAWAREAccount(this), Magnetometer_Provider.getAuthority(this), Bundle.EMPTY ); if (Aware.DEBUG) Log.d(TAG, "Magnetometer service terminated..."); }
/** * Add account to Android system */ private static boolean addAccount(Context context) { Log.d(Constants.TAG, "Adding account..."); AccountManager am = AccountManager.get(context); if (am.addAccountExplicitly(CalendarController.ACCOUNT, null, null)) { // explicitly disable sync ContentResolver.setSyncAutomatically(ACCOUNT, CalendarContract.AUTHORITY, false); ContentResolver.setIsSyncable(ACCOUNT, CalendarContract.AUTHORITY, 0); return true; } else { return false; } }
@Override public void onDestroy() { super.onDestroy(); unregisterReceiver(batteryMonitor); ContentResolver.setSyncAutomatically(Aware.getAWAREAccount(this), Battery_Provider.getAuthority(this), false); ContentResolver.removePeriodicSync( Aware.getAWAREAccount(this), Battery_Provider.getAuthority(this), Bundle.EMPTY ); if (Aware.DEBUG) Log.d(TAG, "Battery service terminated..."); }
@Override public void onDestroy() { super.onDestroy(); unregisterReceiver(installationsMonitor); ContentResolver.setSyncAutomatically(Aware.getAWAREAccount(this), Installations_Provider.getAuthority(this), false); ContentResolver.removePeriodicSync( Aware.getAWAREAccount(this), Installations_Provider.getAuthority(this), Bundle.EMPTY ); if (Aware.DEBUG) Log.d(TAG, "Installations service terminated..."); }
@Override public void onDestroy() { super.onDestroy(); telephonyManager.listen(telephonyState, PhoneStateListener.LISTEN_NONE); ContentResolver.setSyncAutomatically(Aware.getAWAREAccount(this), Telephony_Provider.getAuthority(this), false); ContentResolver.removePeriodicSync( Aware.getAWAREAccount(this), Telephony_Provider.getAuthority(this), Bundle.EMPTY ); if (Aware.DEBUG) Log.d(TAG, "Telephony service terminated..."); }
@Override public void onDestroy() { super.onDestroy(); unregisterReceiver(screenMonitor); ContentResolver.setSyncAutomatically(Aware.getAWAREAccount(this), Screen_Provider.getAuthority(this), false); ContentResolver.removePeriodicSync( Aware.getAWAREAccount(this), Screen_Provider.getAuthority(this), Bundle.EMPTY ); if (Aware.DEBUG) Log.d(TAG, "Screen service terminated..."); }
@Override public void onDestroy() { super.onDestroy(); ContentResolver.setSyncAutomatically(Aware.getAWAREAccount(this), ESM_Provider.getAuthority(this), false); ContentResolver.removePeriodicSync( Aware.getAWAREAccount(this), ESM_Provider.getAuthority(this), Bundle.EMPTY ); unregisterReceiver(esmMonitor); if (Aware.DEBUG) Log.d(TAG, "ESM service terminated..."); }
@Override public void onDestroy() { super.onDestroy(); unregisterReceiver(timezoneObserver); ContentResolver.setSyncAutomatically(Aware.getAWAREAccount(this), TimeZone_Provider.getAuthority(this), false); ContentResolver.removePeriodicSync( Aware.getAWAREAccount(this), TimeZone_Provider.getAuthority(this), Bundle.EMPTY ); if (Aware.DEBUG) Log.d(TAG, "Timezone service terminated..."); } }
@Override public void onDestroy() { super.onDestroy(); telephonyManager.listen(networkTrafficObserver, PhoneStateListener.LISTEN_NONE); ContentResolver.setSyncAutomatically(Aware.getAWAREAccount(this), Traffic_Provider.getAuthority(this), false); ContentResolver.removePeriodicSync( Aware.getAWAREAccount(this), Traffic_Provider.getAuthority(this), Bundle.EMPTY ); if (Aware.DEBUG) Log.d(TAG, "Traffic service terminated..."); } }
@Override public void onDestroy() { super.onDestroy(); ContentResolver.setSyncAutomatically(Aware.getAWAREAccount(this), Keyboard_Provider.getAuthority(this), false); ContentResolver.removePeriodicSync( Aware.getAWAREAccount(this), Keyboard_Provider.getAuthority(this), Bundle.EMPTY ); }
@Override public void onDestroy() { super.onDestroy(); unregisterReceiver(wifiMonitor); if (wifiScan != null) alarmManager.cancel(wifiScan); ContentResolver.setSyncAutomatically(Aware.getAWAREAccount(this), WiFi_Provider.getAuthority(this), false); ContentResolver.removePeriodicSync( Aware.getAWAREAccount(this), WiFi_Provider.getAuthority(this), Bundle.EMPTY ); if (Aware.DEBUG) Log.d(TAG, "WiFi service terminated..."); }
@Override public void onDestroy() { super.onDestroy(); unregisterReceiver(networkMonitor); teleManager.listen(phoneListener, PhoneStateListener.LISTEN_NONE); ContentResolver.setSyncAutomatically(Aware.getAWAREAccount(this), Network_Provider.getAuthority(this), false); ContentResolver.removePeriodicSync( Aware.getAWAREAccount(this), Network_Provider.getAuthority(this), Bundle.EMPTY ); if (Aware.DEBUG) Log.d(TAG, "Network service terminated..."); }
@Override public void onDestroy() { super.onDestroy(); if (PERMISSIONS_OK) locationManager.removeUpdates(this); locationManager.removeGpsStatusListener(gps_status_listener); ContentResolver.setSyncAutomatically(Aware.getAWAREAccount(this), Locations_Provider.getAuthority(this), false); ContentResolver.removePeriodicSync( Aware.getAWAREAccount(this), Locations_Provider.getAuthority(this), Bundle.EMPTY ); if (Aware.DEBUG) Log.d(TAG, "Locations service terminated..."); }
@Override public void onDestroy() { super.onDestroy(); getContentResolver().unregisterContentObserver(callsObs); getContentResolver().unregisterContentObserver(msgsObs); telephonyManager.listen(phoneState, PhoneStateListener.LISTEN_NONE); ContentResolver.setSyncAutomatically(Aware.getAWAREAccount(this), Communication_Provider.getAuthority(this), false); ContentResolver.removePeriodicSync( Aware.getAWAREAccount(this), Communication_Provider.getAuthority(this), Bundle.EMPTY ); if (Aware.DEBUG) Log.d(TAG, TAG + " service terminated..."); } }
public void updatePeriodicSync(MovirtAccount account, boolean syncEnabled) { ObjectUtils.requireNotNull(account, "account"); String authority = OVirtContract.CONTENT_AUTHORITY; Bundle bundle = Bundle.EMPTY; try { ContentResolver.setSyncAutomatically(account.getAccount(), OVirtContract.CONTENT_AUTHORITY, syncEnabled); if (syncEnabled) { long intervalInSeconds = environmentStore.getSharedPreferencesHelper(account).getPeriodicSyncInterval() * (long) Constants.SECONDS_IN_MINUTE; ContentResolver.addPeriodicSync(account.getAccount(), authority, bundle, intervalInSeconds); } else { ContentResolver.removePeriodicSync(account.getAccount(), authority, bundle); } } catch (AccountDeletedException ignored) { } }