Example usage for android.content ContentResolver requestSync

List of usage examples for android.content ContentResolver requestSync

Introduction

In this page you can find the example usage for android.content ContentResolver requestSync.

Prototype

public static void requestSync(SyncRequest request) 

Source Link

Document

Register a sync with the SyncManager.

Usage

From source file:inforuh.eventfinder.sync.SyncAdapter.java

public static void periodicSync(Context context, int interval, int flexTime) {
    Account account = getAccount(context);
    String authority = context.getString(R.string.content_authority);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        SyncRequest request = new SyncRequest.Builder().syncPeriodic(interval, flexTime)
                .setSyncAdapter(account, authority).setExtras(new Bundle()).build();
        ContentResolver.requestSync(request);
    } else {// ww w.j  a  v a  2  s  .  c o  m
        ContentResolver.addPeriodicSync(account, authority, Bundle.EMPTY, interval);
    }
}

From source file:tech.salroid.filmy.syncs.FilmySyncAdapter.java

/**
 * Helper method to schedule the sync adapter periodic execution
 */// w w w. j av a 2s .  co m
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);
    }
}

From source file:com.creationgroundmedia.popularmovies.sync.MovieSyncAdapter.java

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 {//  w  ww  .  ja va2 s.co  m
        ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval);
    }
}

From source file:com.rowland.hashtrace.sync.TweetHashTracerSyncAdapter.java

/**
 * Helper method to schedule the sync adapter periodic execution
 *//* w  ww.j  a v a2 s . com*/
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).build();
        ContentResolver.requestSync(request);
    } else {
        ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval);
    }
}

From source file:com.katamaditya.apps.weather4u.weathersync.Weather4USyncAdapter.java

/**
 * Helper method to schedule the sync adapter periodic execution
 *///from  w  ww.  j a  va 2s  .  c  om
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);
    }
}

From source file:com.ravi.apps.android.newsbytes.sync.NewsSyncAdapter.java

/**
 * Schedules periodic execution of the sync adapter.
 *//*from  w ww  .  j a  v  a  2  s.  c  o  m*/
public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) {
    // Get account and authority.
    Account account = getSyncAccount(context);
    String authority = context.getString(R.string.content_authority);

    // Set inexact timer for the periodic sync for KitKat and above.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        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);
    }
}

From source file:com.skywomantechnology.app.guildviewer.sync.GuildViewerSyncAdapter.java

/**
 * Set up the sync to run at periodic intervals.
 *
 * @param context//from w  w w.j  av a 2  s  .  c o  m
 *         current application environment context
 * @param syncInterval
 *         how often to sync in seconds
 * @param flexTime
 *         how many seconds can it run before syncInterval (inexact timer for versions greater
 *         than KITKAT
 */
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).build();
        ContentResolver.requestSync(request);
    } else {
        ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval);
    }
}

From source file:com.jackie.sunshine.app.sync.SunshineSyncAdapter.java

/**
 * Helper method to schedule the sync adapter periodic execution
 *///from  ww  w  .ja v a 2s .c  o  m
public static void configurePeriodicSync(Context context, long syncInterval, long flexTime) {
    Account account = getSyncAccount(context);
    String authority = context.getString(R.string.content_authority);
    SyncRequest request = new SyncRequest.Builder().syncPeriodic(syncInterval, flexTime)
            .setSyncAdapter(account, authority).setExtras(new Bundle()).build();
    ContentResolver.requestSync(request);
}

From source file:com.example.igorklimov.popularmoviesdemo.sync.SyncAdapter.java

private static void configurePeriodicSync(Context context, int syncInterval, int flexTime) {
    String authority = context.getString(R.string.content_authority);
    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(syncInterval, flexTime)
                .setSyncAdapter(account, authority).setExtras(new Bundle()).build();
        ContentResolver.requestSync(request);
    } else {/*from w  w w  . j a v a2 s.c o  m*/
        ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval);
    }
}

From source file:com.adkdevelopment.earthquakesurvival.data.syncadapter.SyncAdapter.java

/**
 * Helper method to schedule the sync adapter periodic execution
 *//*from  w  w  w  .j a  va 2s .  c  o m*/
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);
        }
    }
}