/** * Based on https://gist.github.com/udacityandroid/7230489fb8cb3f46afee */ private static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { Account account = getSyncAccount(context, syncInterval, flexTime); String authority = context.getString(R.string.rnsb_content_authority); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // We can enable inexact timers in our periodic sync (better for batter life) SyncRequest request = new SyncRequest.Builder(). syncPeriodic(syncInterval, flexTime). setSyncAdapter(account, authority). setExtras(new Bundle()).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
/** * Helper method to schedule the sync adapter periodic execution */ public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // we can enable inexact timers in our periodic sync SyncRequest request = new SyncRequest.Builder(). syncPeriodic(syncInterval, flexTime). setSyncAdapter(account, authority). setExtras(new Bundle()).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
/** * Helper method to schedule the sync adapter periodic execution */ public static void configurePeriodicSync(Context context, long syncInterval, long flexTime) { Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // we can enable inexact timers in our periodic sync SyncRequest request = new SyncRequest.Builder(). syncPeriodic(syncInterval, flexTime). setSyncAdapter(account, authority). setExtras(new Bundle()).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
/** * Helper method to schedule the sync adapter periodic execution */ public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { Account account = getSyncAccount(context); String authority = context.getString(R.string.contentauthority); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // we can enable inexact timers in our periodic sync SyncRequest request = new SyncRequest.Builder(). syncPeriodic(syncInterval, flexTime). setSyncAdapter(account, authority). setExtras(new Bundle()).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
/** * Helper method to schedule the sync adapter periodic execution */ public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { Account account = getSyncAccount(context); String authority = context.getString(R.string.sync_provider_authority); if (syncInterval == -1) { ContentResolver.setSyncAutomatically(account, context.getString(R.string.sync_provider_authority), false); } else { ContentResolver.setSyncAutomatically(account, context.getString(R.string.sync_provider_authority), true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // we can enable inexact timers in our periodic sync SyncRequest request = new SyncRequest.Builder(). syncPeriodic(syncInterval, flexTime). setSyncAdapter(account, authority). setExtras(new Bundle()).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } } }
private static void configurePeriodicSync(Context context, int syncInterval, int syncFlextime) { Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // we can enable inexact timers in our periodic sync try { SyncRequest request = new SyncRequest.Builder(). syncPeriodic(syncInterval, syncFlextime). setSyncAdapter(account, authority).build(); ContentResolver.requestSync(request); } catch (Exception e) { } } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // we can enable inexact timers in our periodic sync SyncRequest request = new SyncRequest.Builder() .syncPeriodic(syncInterval, flexTime) .setSyncAdapter(account, authority) .setExtras(new Bundle()) .build(); ContentResolver.requestSync(request); ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
/** * Set synchronisation everyday with 4 hours flexible time * @param context * @param account */ private static void setPeriodicSync(Context context, Account account) { String authority = context.getResources().getString(R.string.content_authority); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // we can enable inexact timers in our periodic sync SyncRequest request = new SyncRequest.Builder(). syncPeriodic(SYNC_INTERVAL, SYNC_FLEXTIME). setSyncAdapter(account, authority). setExtras(Bundle.EMPTY).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync( account, authority, Bundle.EMPTY, SYNC_INTERVAL); } ContentResolver.setSyncAutomatically(account, context.getString(R.string.content_authority), true); }
/** * Helper method to schedule periodic execution of a sync adapter. * flexTime is only used on KitKat and newer devices. */ public static void configurePeriodicSync(Account account, String authority, int syncInterval, int flexTime) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // we can enable inexact timers in our periodic sync SyncRequest request = new SyncRequest.Builder() .syncPeriodic(syncInterval, flexTime) .setSyncAdapter(account, authority) .setExtras(Bundle.EMPTY) .build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, Bundle.EMPTY, syncInterval); } }
public void syncAsUser(SyncRequest request, int userId) { Account account = mirror.android.content.SyncRequest.mAccountToSync.get(request); String authority = mirror.android.content.SyncRequest.mAuthority.get(request); Bundle extras = mirror.android.content.SyncRequest.mExtras.get(request); boolean isPeriodic = mirror.android.content.SyncRequest.mIsPeriodic.get(request); long syncRunTimeSecs = mirror.android.content.SyncRequest.mSyncRunTimeSecs.get(request); if (!isAccountExist(userId, account, authority)) { return; } VSyncRecord.SyncRecordKey key = new VSyncRecord.SyncRecordKey(account, authority); VSyncRecord.SyncExtras syncExtras = new VSyncRecord.SyncExtras(extras); int isSyncable = getIsSyncableAsUser(account, authority, userId); synchronized (mRecords) { Map<VSyncRecord.SyncRecordKey, VSyncRecord> map = mRecords.get(userId); if (map == null) { map = new HashMap<>(); mRecords.put(userId, map); } VSyncRecord record = map.get(key); if (record == null) { record = new VSyncRecord(userId, account, authority); map.put(key, record); } if (isSyncable < 0) { // Initialisation sync. Bundle newExtras = new Bundle(); newExtras.putBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, true); record.extras.add(new VSyncRecord.SyncExtras(newExtras)); } if (isPeriodic) { VSyncRecord.PeriodicSyncConfig periodicSyncConfig = new VSyncRecord.PeriodicSyncConfig(syncRunTimeSecs); record.configs.put(syncExtras, periodicSyncConfig); } else { record.extras.add(syncExtras); } } }
/** * Helper method to schedule the sync adapter periodic execution */ private static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { SyncRequest request = new SyncRequest.Builder(). syncPeriodic(syncInterval, flexTime). setSyncAdapter(mAccount, context.getString(R.string.sync_authority)). setExtras(new Bundle()).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(mAccount, context.getString(R.string.sync_authority), new Bundle(), syncInterval); } }
protected void startSynchronization() { Log_OC.d(TAG, "Got to start sync"); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) { Log_OC.d(TAG, "Canceling all syncs for " + MainApp.getAuthority()); ContentResolver.cancelSync(null, MainApp.getAuthority()); // cancel the current synchronizations of any ownCloud account Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); Log_OC.d(TAG, "Requesting sync for " + getAccount().name + " at " + MainApp.getAuthority()); ContentResolver.requestSync( getAccount(), MainApp.getAuthority(), bundle); } else { Log_OC.d(TAG, "Requesting sync for " + getAccount().name + " at " + MainApp.getAuthority() + " with new API"); SyncRequest.Builder builder = new SyncRequest.Builder(); builder.setSyncAdapter(getAccount(), MainApp.getAuthority()); builder.setExpedited(true); builder.setManual(true); builder.syncOnce(); // Fix bug in Android Lollipop when you click on refresh the whole account Bundle extras = new Bundle(); builder.setExtras(extras); SyncRequest request = builder.build(); ContentResolver.requestSync(request); } }
public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // we can enable inexact timers in our periodic sync SyncRequest request = new SyncRequest.Builder(). syncPeriodic(syncInterval, flexTime). setSyncAdapter(account, authority). setExtras(new Bundle()).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { SyncRequest syncRequest = new SyncRequest.Builder(). syncPeriodic(syncInterval, flexTime). setSyncAdapter(account, authority). setExtras(new Bundle()).build(); ContentResolver.requestSync(syncRequest); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
/** * Helper method to schedule the sync adapter periodic execution */ private static void configurePeriodicSync(Context context) { Account account = getSyncAccount(context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // we can enable inexact timers in our periodic sync SyncRequest request = new SyncRequest.Builder(). syncPeriodic(VertretungsplanSyncAdapter.SYNC_INTERVAL, VertretungsplanSyncAdapter.SYNC_FLEXTIME). setSyncAdapter(account, VertretungsplanContract.CONTENT_AUTHORITY).setExtras(new Bundle()).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, VertretungsplanContract.CONTENT_AUTHORITY, new Bundle(), VertretungsplanSyncAdapter.SYNC_INTERVAL); } }
private static void configurePeriodicSync(Context context) { Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { SyncRequest request = new SyncRequest.Builder(). syncPeriodic(SyncAdapter.SYNC_INTERVAL, SyncAdapter.SYNC_FLEXTIME). setSyncAdapter(account, authority). setExtras(new Bundle()).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), SyncAdapter.SYNC_INTERVAL); } }