Example usage for android.content ContentResolver SYNC_EXTRAS_MANUAL

List of usage examples for android.content ContentResolver SYNC_EXTRAS_MANUAL

Introduction

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

Prototype

String SYNC_EXTRAS_MANUAL

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

Click Source Link

Document

Setting this extra is the equivalent of setting both #SYNC_EXTRAS_IGNORE_SETTINGS and #SYNC_EXTRAS_IGNORE_BACKOFF

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   w  w w.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
 *//*  w w w .  j a v  a  2s .c o  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:io.github.hidroh.materialistic.data.ItemSyncAdapter.java

@UiThread
static void initSync(Context context, @Nullable String itemId) {
    if (!Preferences.Offline.isEnabled(context)) {
        return;/*from w ww  .jav a 2  s  .c o  m*/
    }
    Bundle extras = new Bundle();
    if (itemId != null) {
        extras.putString(ItemSyncAdapter.EXTRA_ID, itemId);
    }
    extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    extras.putBoolean(ItemSyncAdapter.EXTRA_CONNECTION_ENABLED,
            Preferences.Offline.currentConnectionEnabled(context));
    extras.putBoolean(ItemSyncAdapter.EXTRA_READABILITY_ENABLED,
            Preferences.Offline.isReadabilityEnabled(context));
    extras.putBoolean(ItemSyncAdapter.EXTRA_COMMENTS_ENABLED, Preferences.Offline.isCommentsEnabled(context));
    extras.putBoolean(ItemSyncAdapter.EXTRA_NOTIFICATION_ENABLED,
            Preferences.Offline.isNotificationEnabled(context));
    ContentResolver.requestSync(Application.createSyncAccount(), MaterialisticProvider.PROVIDER_AUTHORITY,
            extras);
}

From source file:com.manning.androidhacks.hack023.MainActivity.java

public void refresh(View v) {
    Bundle extras = new Bundle();
    extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);

    Account account = ((HackApplication) getApplication()).getCurrentAccount();

    if (ContentResolver.isSyncPending(account, TodoContentProvider.AUTHORITY)) {
        ContentResolver.cancelSync(account, TodoContentProvider.AUTHORITY);
    }/*from   ww  w . j  ava 2s  .c  o  m*/

    ContentResolver.requestSync(account, TodoContentProvider.AUTHORITY, extras);
}

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:dev.drsoran.moloko.sync.util.SyncUtils.java

public final static void requestManualSync(Account account) {
    final Bundle bundle = new Bundle();

    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, true);

    ContentResolver.requestSync(account, Rtm.AUTHORITY, bundle);
}

From source file:org.kontalk.sync.SyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {//from   w  w  w  .  ja  v  a2s.c  o m

    try {
        // broadcast sync start
        mBroadcastManager.sendBroadcast(new Intent(ACTION_SYNC_START));

        final long startTime = SystemClock.elapsedRealtime();
        boolean force = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);

        // do not start if offline
        if (Preferences.getOfflineMode()) {
            Log.d(TAG, "not requesting sync - offline mode");
            return;
        }

        // do not start if no server available (limbo state)
        if (Preferences.getEndpointServer(mContext) == null) {
            Log.d(TAG, "no server available - aborting");
            return;
        }

        if (!force) {
            if (isThrottling()) {
                Log.d(TAG, "not starting sync - throttling");
                // TEST do not delay - syncResult.delayUntil = (long) diff;
                return;
            }
        }

        Log.i(TAG, "sync started (authority=" + authority + ")");
        // avoid other syncs to get scheduled in the meanwhile
        Preferences.setLastSyncTimestamp(System.currentTimeMillis());

        ContentProviderClient usersProvider = getContext().getContentResolver()
                .acquireContentProviderClient(UsersProvider.AUTHORITY);

        try {
            // hold a reference to the message center while syncing
            MessageCenterService.hold(mContext, true);
            // start sync
            mSyncer = new Syncer(mContext);
            mSyncer.performSync(mContext, account, authority, provider, usersProvider, syncResult);
        } catch (OperationCanceledException e) {
            Log.w(TAG, "sync canceled!", e);
        } finally {
            // release the message center
            MessageCenterService.release(mContext);
            // release user provider
            usersProvider.release();

            Preferences.setLastSyncTimestamp(System.currentTimeMillis());
            // some stats :)
            long endTime = SystemClock.elapsedRealtime();
            Log.d(TAG, String.format("sync took %.5f seconds", ((float) (endTime - startTime)) / 1000));
        }
    } finally {
        // broadcast sync finish
        mBroadcastManager.sendBroadcast(new Intent(ACTION_SYNC_FINISH));
    }
}

From source file:dev.drsoran.moloko.sync.util.SyncUtils.java

public final static void requestSettingsOnlySync(Context context, Account account) {
    if (account != null) {
        final Bundle bundle = new Bundle();

        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        bundle.putBoolean(dev.drsoran.moloko.sync.Constants.SYNC_EXTRAS_ONLY_SETTINGS, true);
        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, false);

        ContentResolver.requestSync(account, Rtm.AUTHORITY, bundle);
    } else {//from  w  w w .  jav a  2s.  co  m
        // TODO: Show NoAccountDialogFragment if we use PreferenceFragment
        context.startActivity(Intents.createNewAccountIntent());
    }
}

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// w w  w  .j  av  a2 s . co 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);
        }
    });
}