Example usage for android.content ContentResolver SYNC_EXTRAS_EXPEDITED

List of usage examples for android.content ContentResolver SYNC_EXTRAS_EXPEDITED

Introduction

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

Prototype

String SYNC_EXTRAS_EXPEDITED

To view the source code for android.content ContentResolver SYNC_EXTRAS_EXPEDITED.

Click Source Link

Document

If this extra is set to true, the sync request will be scheduled at the front of the sync request queue and without any delay

Usage

From source file:com.example.android.sampletvinput.syncservice.SyncUtils.java

public static void requestSync(Context context, String inputId, boolean currentProgramOnly) {
    PersistableBundle pBundle = new PersistableBundle();
    pBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    pBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    pBundle.putString(SyncJobService.BUNDLE_KEY_INPUT_ID, inputId);
    pBundle.putBoolean(SyncJobService.BUNDLE_KEY_CURRENT_PROGRAM_ONLY, currentProgramOnly);
    JobInfo.Builder builder = new JobInfo.Builder(REQUEST_SYNC_JOB_ID,
            new ComponentName(context, SyncJobService.class));
    JobInfo jobInfo = builder.setExtras(pBundle).setOverrideDeadline(SyncJobService.OVERRIDE_DEADLINE_MILLIS)
            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).build();
    scheduleJob(context, jobInfo);/*from  www  .  j a  v a2  s.c o  m*/
    Intent intent = new Intent(SyncJobService.ACTION_SYNC_STATUS_CHANGED);
    intent.putExtra(SyncJobService.BUNDLE_KEY_INPUT_ID, inputId);
    intent.putExtra(SyncJobService.SYNC_STATUS, SyncJobService.SYNC_STARTED);
    LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}

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

/**
 * Helper method to have the sync adapter sync immediately
 *
 * @param context The context used to access the account service
 *///from w w w  .  j ava  2 s.co  m
public static void syncImmediately(Context context) {

    Bundle bundle = new Bundle();
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    ContentResolver.requestSync(getSyncAccount(context), context.getString(R.string.content_authority), bundle);
}

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

public static void startSync(Context context) {
    Bundle bundle = new Bundle();
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    ContentResolver.requestSync(getAccount(context), context.getString(R.string.content_authority), bundle);
}

From source file:edu.mit.mobile.android.locast.sync.LocastSyncService.java

/**
 * Convenience method to request a sync.
 *
 * This wraps {@link ContentResolver#requestSync(Account, String, Bundle)}
 * and fills in the necessary extras./*from  w ww .  j  a  va2s .c  o  m*/
 *
 * @param account
 * @param what the uri of the item that needs to be sync'd. can be null
 * @param explicitSync
 *            if true, adds {@link ContentResolver#SYNC_EXTRAS_MANUAL} to
 *            the extras
 * @param extras
 */
public static void startSync(Account account, Uri what, Bundle extras) {

    if (what != null) {
        extras.putString(LocastSyncService.EXTRA_SYNC_URI, what.toString());
    }

    if (extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false)) {
        if (SYNC_ADAPTER != null) {
            if (DEBUG) {
                Log.d(TAG, "canceling current sync to make room for expedited sync of " + what);
            }
            // only cancel the ongoing sync, to leave the queue untouched.
            SYNC_ADAPTER.cancelCurrentSync();
        }
    }

    if (DEBUG) {
        Log.d(TAG, "requesting sync for " + account + " with extras: " + extras);
    }
    ContentResolver.requestSync(account, MediaProvider.AUTHORITY, extras);
}

From source file:com.activiti.android.app.fragments.labs.LabsMenuFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    Button sync = (Button) viewById(R.id.app_sync);
    sync.setOnClickListener(new View.OnClickListener() {
        @Override/*from w  ww .java2s . c o m*/
        public void onClick(View v) {
            List<Account> accounts = ActivitiAccountManager.getInstance(getActivity()).getAndroidAccounts();
            Bundle settingsBundle = new Bundle();
            settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
            settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
            ContentResolver.requestSync(accounts.get(0), ProcessDefinitionModelProvider.AUTHORITY,
                    settingsBundle);
        }
    });
}

From source file:com.activiti.android.platform.provider.transfer.ContentTransferManager.java

public static void downloadTransfer(Context activity, String name, String mimetype, String contentId) {
    Bundle settingsBundle = new Bundle();
    settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    settingsBundle.putInt(ContentTransferSyncAdapter.ARGUMENT_MODE, ContentTransferSyncAdapter.MODE_OPEN_IN);
    settingsBundle.putString(ContentTransferSyncAdapter.ARGUMENT_FILE_PATH, name);
    settingsBundle.putString(ContentTransferSyncAdapter.ARGUMENT_CONTENT_ID, contentId);
    settingsBundle.putString(ContentTransferSyncAdapter.ARGUMENT_MIMETYPE, mimetype);
    ContentResolver.requestSync(ActivitiAccountManager.getInstance(activity).getCurrentAndroidAccount(),
            ContentTransferProvider.AUTHORITY, settingsBundle);
}

From source file:com.openerp.services.MailGroupSyncService.java

public void performSync(Context context, Account account, Bundle extras, String authority,
        ContentProviderClient provider, SyncResult syncResult) {

    try {//  www . java2 s .c  o m
        Intent intent = new Intent();
        intent.setAction(SyncFinishReceiver.SYNC_FINISH);

        MailGroupDB db = new MailGroupDB(context);
        db.setAccountUser(OpenERPAccountManager.getAccountDetail(context, account.name));
        OEHelper oe = db.getOEInstance();
        if (oe != null && oe.syncWithServer(true)) {
            MailFollowers followers = new MailFollowers(context);

            OEDomain domain = new OEDomain();
            domain.add("partner_id", "=", oe.getUser().getPartner_id());
            domain.add("res_model", "=", db.getModelName());

            if (followers.getOEInstance().syncWithServer(domain, true)) {
                // syncing group messages
                JSONArray group_ids = new JSONArray();
                for (OEDataRow grp : followers.select("res_model = ? AND partner_id = ?",
                        new String[] { db.getModelName(), oe.getUser().getPartner_id() + "" })) {
                    group_ids.put(grp.getInt("res_id"));
                }
                Bundle messageBundle = new Bundle();
                messageBundle.putString("group_ids", group_ids.toString());
                messageBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
                messageBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
                ContentResolver.requestSync(account, MessageProvider.AUTHORITY, messageBundle);

            }
        }
        if (OpenERPAccountManager.currentUser(context).getAndroidName().equals(account.name))
            context.sendBroadcast(intent);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:co.carlosjimenez.android.currencyalerts.app.sync.ForexSyncAdapter.java

/**
 * Helper method to have the sync adapter sync immediately
 *
 * @param context The context used to access the account service
 *//* w w w .java2s  .com*/
public static void syncImmediately(Context context) {
    Bundle bundle = new Bundle();
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    ContentResolver.requestSync(getSyncAccount(context), context.getString(R.string.content_authority), bundle);
}

From source file:com.alphabetbloc.accessmrs.services.SyncManager.java

public static void syncData() {
    if (App.DEBUG)
        Log.v(TAG, "SyncData is Requested");
    AccountManager accountManager = AccountManager.get(App.getApp());
    Account[] accounts = accountManager.getAccountsByType(App.getApp().getString(R.string.app_account_type));
    if (accounts.length > 0) {

        sStartSync.set(true);//w  w  w. ja va2 s  . co m

        Bundle bundle = new Bundle();
        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_FORCE, true);
        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);

        // //this resets the scheduled sync
        ContentResolver.requestSync(accounts[0], App.getApp().getString(R.string.app_provider_authority),
                bundle);
    } else
        UiUtils.toastAlert(App.getApp().getString(R.string.sync_error),
                App.getApp().getString(R.string.no_account_setup));
}

From source file:edu.mit.mobile.android.locast.sync.LocastSimpleSyncService.java

public void enqueueItem(Uri uri, Bundle extras) {

    final boolean expedited = extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false);
    final boolean manual = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);

    final SyncItem i = new SyncItem(uri, extras, (expedited ? 10 : 0) + (manual ? 5 : 0));

    if (!expedited && mPriorityQueue.contains(i)) {
        Log.d(TAG, "not adding " + i + " as it's already in the sync queue");
        return;//  w  w w. j  a v  a  2  s . c  om
    }

    mPriorityQueue.add(i);
    Log.d(TAG, "enqueued " + i);
}