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.creationgroundmedia.popularmovies.sync.MovieSyncAdapter.java

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.odoo.MainActivity.java

/**
 * Request sync./*from  ww w.j av a2s .  c  om*/
 * 
 * @param authority
 *            the authority
 * @param bundle
 *            the extra data
 */
public void requestSync(String authority, Bundle bundle) {
    Account account = OdooAccountManager.getAccount(getApplicationContext(),
            OUser.current(getApplicationContext()).getAndroidName());
    Bundle settingsBundle = new Bundle();
    settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    if (bundle != null) {
        settingsBundle.putAll(bundle);
    }
    ContentResolver.requestSync(account, authority, settingsBundle);
}

From source file:org.ohmage.app.SurveyActivity.java

public synchronized void submit() {
    isFinished = true;//  w  w w .j  a v a  2 s .co m

    // Tell reminders that the survey was taken
    TriggerFramework.notifySurveyTaken(this, Surveys.getId(getIntent().getData()));

    ContentValues values = new ContentValues();
    values.put(Responses.SURVEY_ID, Surveys.getId(getIntent().getData()));
    values.put(Responses.SURVEY_VERSION, Surveys.getVersion(getIntent().getData()));
    if (mLocationClient != null && mLocationClient.isConnected()) {
        values.put(Responses.RESPONSE_METADATA, new StreamPointBuilder().now().withId()
                .withLocation(mLocationClient.getLastLocation()).getMetadata());
    } else {
        values.put(Responses.RESPONSE_METADATA, new StreamPointBuilder().now().withId().getMetadata());
    }

    mPagerAdapter.buildResponse(values);
    getContentResolver().insert(Responses.CONTENT_URI, values);
    Toast.makeText(this, "The response has been submitted. Thank you!", Toast.LENGTH_SHORT).show();
    AppLogManager.getInstance().logInfo(this, "SurveySubmitted",
            "User submitted the survey: " + Surveys.getId(getIntent().getData()));

    // Force a sync to upload data
    Bundle settingsBundle = new Bundle();
    settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);

    Account[] accounts = am.getAccountsByType(AuthUtil.ACCOUNT_TYPE);
    if (accounts.length == 1) {
        Account account = accounts[0];
        getContentResolver().requestSync(account, ResponseContract.CONTENT_AUTHORITY, settingsBundle);
        getContentResolver().requestSync(account, AppLogSyncAdapter.CONTENT_AUTHORITY, settingsBundle);
    }
    finish();
}

From source file:net.abcdroid.devfest12.ui.HomeActivity.java

private void triggerRefresh() {
    Bundle extras = new Bundle();
    extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    if (!UIUtils.isGoogleTV(this)) {
        ContentResolver.requestSync(//from   w  w  w .  j  ava 2s  . c om
                new Account(AccountUtils.getChosenAccountName(this), GoogleAccountManager.ACCOUNT_TYPE),
                ScheduleContract.CONTENT_AUTHORITY, extras);
    }

    if (mSocialStreamFragment != null) {
        mSocialStreamFragment.refresh();
    }
}

From source file:org.exfio.csyncdroid.syncadapter.WeaveSyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {//  ww  w  .  java2  s.c  o m
    Log.i(TAG, "Performing sync for authority " + authority);

    // set class loader for iCal4j ResourceLoader
    Thread.currentThread().setContextClassLoader(getContext().getClassLoader());

    //DEBUG only
    if (SystemUtils.isDebuggable(getContext())) {
        org.exfio.csyncdroid.util.Log.init("debug");
    }

    AccountSettings accountSettings = null;

    if (account.type.equals(Constants.ACCOUNT_TYPE_FXACCOUNT)
            || account.type.equals(Constants.ACCOUNT_TYPE_CSYNC)) {

        FxAccountAccountSettings fxaSettings = new FxAccountAccountSettings(getContext(), account);

        Log.d(TAG, String.format("FxA credentials - username: %s, password: %s", fxaSettings.getUserName(),
                fxaSettings.getPassword()));

        //get weave account params
        FxAccountParams fxaParams = new FxAccountParams();
        fxaParams.accountServer = fxaSettings.getAccountServer();
        fxaParams.tokenServer = fxaSettings.getTokenServer();
        fxaParams.user = fxaSettings.getUserName();
        fxaParams.password = fxaSettings.getPassword();
        fxaParams.email = fxaSettings.getEmail();

        try {
            ExtendedJSONObject jsonObject = ExtendedJSONObject
                    .parseJSONObject(fxaSettings.getBrowserIdCertificate());
            fxaParams.browserIdCertificate = FxAccountCertificate.fromJSONObject(jsonObject);
        } catch (WeaveException | NonObjectJSONException | IOException | ParseException e) {
            Log.e(TAG, "Couldn't parse BrowserID certificate and key pair - " + e.getMessage());
            return;
        }

        fxaParams.kB = Base64.decodeBase64(fxaSettings.getKb());

        //Sync token expires within 5 min so we need to get it each session. Why bother caching?
        //try {
        //   ExtendedJSONObject jsonObject = ExtendedJSONObject.parseJSONObject(fxaSettings.getSyncToken());
        //   fxaParams.syncToken = FxAccountSyncToken.fromJSONObject(jsonObject);
        //} catch (WeaveException | NonObjectJSONException | IOException | ParseException e) {
        //   Log.e(TAG, "Couldn't parse Sync Token - " + e.getMessage());
        //   return;
        //}

        //Initialise weave account
        try {
            weaveAccount = new FxAccount();
            weaveAccount.init(fxaParams);
        } catch (WeaveException e) {
            Log.e(TAG, e.getMessage());
            return;
        }

        accountSettings = fxaSettings;

    } else if (account.type.equals(Constants.ACCOUNT_TYPE_LEGACYV5)) {

        LegacyV5AccountSettings wslSettings = new LegacyV5AccountSettings(getContext(), account);

        Log.d(TAG, String.format("Weave Sync V5 credentials - username: %s, password: %s, synckey: %s",
                wslSettings.getUserName(), wslSettings.getPassword(), wslSettings.getSyncKey()));

        //get weave account params
        LegacyV5AccountParams wslParams = new LegacyV5AccountParams();
        wslParams.accountServer = wslSettings.getBaseURL();
        wslParams.user = wslSettings.getUserName();
        wslParams.password = wslSettings.getPassword();
        wslParams.syncKey = wslSettings.getSyncKey();

        //Initialise weave account
        try {
            weaveAccount = new LegacyV5Account();
            weaveAccount.init(wslParams);
        } catch (WeaveException e) {
            Log.e(TAG, e.getMessage());
            return;
        }

        accountSettings = wslSettings;

    } else {

        ExfioPeerAccountSettings epSettings = new ExfioPeerAccountSettings(getContext(), account);

        Log.d(TAG, String.format("eXfio Peer credentials - username: %s, password: %s, synckey: %s",
                epSettings.getUserName(), epSettings.getPassword(), epSettings.getSyncKey()));

        //get weave account params
        LegacyV5AccountParams wslParams = new LegacyV5AccountParams();
        wslParams.accountServer = epSettings.getBaseURL();
        wslParams.user = epSettings.getUserName();
        wslParams.password = epSettings.getPassword();
        wslParams.syncKey = epSettings.getSyncKey();

        //Initialise weave account
        try {
            weaveAccount = new LegacyV5Account();
            weaveAccount.init(wslParams);
        } catch (WeaveException e) {
            Log.e(TAG, e.getMessage());
            return;
        }

        //TODO - Refactor to remove use of module vars
        //processExfioPeerMessages re-initialises weaveAccount when changing from pending to authorised
        try {
            processExfioPeerMessages(account);
        } catch (WeaveException e) {
            Log.e(TAG, e.getMessage());
            return;
        } finally {
            //processExfioPeerMessages also initialises weaveClient so make sure it has been closed
            closeWeaveClient();
        }

        accountSettings = epSettings;
    }

    try {
        weaveClient = WeaveClientFactory.getInstance(weaveAccount);
    } catch (WeaveException e) {
        Log.e(TAG, e.getMessage());
        closeWeaveClient();
        return;
    }

    //Update settings, i.e. sync token and/or browser id certificate
    try {
        accountSettings.updateAccount(weaveAccount.accountParamsToProperties());
    } catch (Exception e) {
        Log.e(TAG, String.format("Error updating account - %s", e.getMessage()));
    }

    //getSyncPairs() overridden by implementing classes, i.e. ContactsSyncAdapter 
    Map<LocalCollection<?>, WeaveCollection<?>> syncCollections = null;
    try {
        syncCollections = getSyncPairs(account, provider, weaveClient);
    } catch (WeaveException e) {
        Log.e(TAG, e.getMessage());
        closeWeaveClient();
        return;
    }

    if (syncCollections == null)
        Log.i(TAG, "Nothing to synchronize");
    else {
        try {
            for (Map.Entry<LocalCollection<?>, WeaveCollection<?>> entry : syncCollections.entrySet())
                new SyncManager(entry.getKey(), entry.getValue())
                        .synchronize(extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL), syncResult);

        } catch (WeaveException ex) {
            syncResult.stats.numParseExceptions++;
            Log.e(TAG, "Invalid Weave response", ex);

            //FIXME - log sync status

            //         } catch (HttpException ex) {
            //            if (ex.getCode() == HttpStatus.SC_UNAUTHORIZED) {
            //               Log.e(TAG, "HTTP Unauthorized " + ex.getCode(), ex);
            //               syncResult.stats.numAuthExceptions++;
            //            } else if (ex.isClientError()) {
            //               Log.e(TAG, "Hard HTTP error " + ex.getCode(), ex);
            //               syncResult.stats.numParseExceptions++;
            //            } else {
            //               Log.w(TAG, "Soft HTTP error " + ex.getCode() + " (Android will try again later)", ex);
            //               syncResult.stats.numIoExceptions++;
            //            }

        } catch (LocalStorageException ex) {
            syncResult.databaseError = true;
            Log.e(TAG, "Local storage (content provider) exception", ex);
            //         } catch (IOException ex) {
            //            syncResult.stats.numIoExceptions++;
            //            Log.e(TAG, "I/O error (Android will try again later)", ex);
        } finally {
            // close weave http client
            closeWeaveClient();
        }
    }
}

From source file:com.google.android.media.tv.companionlibrary.EpgSyncJobService.java

/**
 * Manually requests a job to run now.//from  ww  w. j  a  v  a  2  s  . c  o  m
 *
 * To check the current status of the sync, register a {@link android.content.BroadcastReceiver}
 * with an {@link android.content.IntentFilter} which checks for the action
 * {@link #ACTION_SYNC_STATUS_CHANGED}.
 * <p />
 * The sync status is an extra parameter in the {@link Intent} with key
 * {@link #SYNC_STATUS}. The sync status is either {@link #SYNC_STARTED} or
 * {@link #SYNC_FINISHED}.
 * <p />
 * Check that the value of {@link #BUNDLE_KEY_INPUT_ID} matches your
 * {@link android.media.tv.TvInputService}. If you're calling this from your setup activity,
 * you can get the extra parameter {@link TvInputInfo#EXTRA_INPUT_ID}.
 * <p />
 * @param context Application's context.
 * @param inputId Component name for the app's TvInputService. This can be received through an
 * Intent extra parameter {@link TvInputInfo#EXTRA_INPUT_ID}.
 * @param syncDuration The duration of EPG content to fetch in milliseconds. For a manual sync,
 * this should be relatively short. For a background sync this should be long.
 * @param jobServiceComponent The {@link EpgSyncJobService} class that will run.
 */
public static void requestImmediateSync(Context context, String inputId, long syncDuration,
        ComponentName jobServiceComponent) {
    if (jobServiceComponent.getClass().isAssignableFrom(EpgSyncJobService.class)) {
        throw new IllegalArgumentException("This class does not extend EpgSyncJobService");
    }
    PersistableBundle persistableBundle = new PersistableBundle();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    }
    persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    persistableBundle.putString(EpgSyncJobService.BUNDLE_KEY_INPUT_ID, inputId);
    persistableBundle.putLong(EpgSyncJobService.BUNDLE_KEY_SYNC_PERIOD, syncDuration);
    JobInfo.Builder builder = new JobInfo.Builder(REQUEST_SYNC_JOB_ID, jobServiceComponent);
    JobInfo jobInfo = builder.setExtras(persistableBundle)
            .setOverrideDeadline(EpgSyncJobService.OVERRIDE_DEADLINE_MILLIS)
            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).build();
    scheduleJob(context, jobInfo);
    if (DEBUG) {
        Log.d(TAG, "Single job scheduled");
    }
}

From source file:at.bitfire.davdroid.syncadapter.SyncManager.java

/**
 * Checks the current sync state (e.g. CTag) and whether synchronization from remote is required.
 * @return <ul>//from   w  w w  .  java2 s. c om
 *      <li><code>true</code>   if the remote collection has changed, i.e. synchronization from remote is required</li>
 *      <li><code>false</code>  if the remote collection hasn't changed</li>
 * </ul>
 */
protected boolean checkSyncState() throws CalendarStorageException, ContactsStorageException {
    // check CTag (ignore on manual sync)
    GetCTag getCTag = (GetCTag) davCollection.properties.get(GetCTag.NAME);
    if (getCTag != null)
        remoteCTag = getCTag.cTag;

    String localCTag = null;
    if (extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL))
        App.log.info("Manual sync, ignoring CTag");
    else
        localCTag = localCollection.getCTag();

    if (remoteCTag != null && remoteCTag.equals(localCTag)) {
        App.log.info("Remote collection didn't change (CTag=" + remoteCTag + "), no need to query children");
        return false;
    } else
        return true;
}

From source file:dev.drsoran.moloko.sync.SyncAdapter.java

private final boolean shouldProcessRequest(Bundle bundle) {
    return (bundle != null && (bundle.containsKey(ContentResolver.SYNC_EXTRAS_INITIALIZE)
            || bundle.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL)
            || bundle.containsKey(dev.drsoran.moloko.sync.Constants.SYNC_EXTRAS_SCHEDULED)));
}

From source file:com.nextgis.mobile.fragment.LayersFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.sync:
        for (Account account : mAccounts) {
            Bundle settingsBundle = new Bundle();
            settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
            settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);

            ContentResolver.requestSync(account, AUTHORITY, settingsBundle);
        }/*from   w  ww  . j av a2 s . co m*/

        updateInfo();
        break;
    case R.id.new_layer:
        mNewLayer.showContextMenu();
        break;
    }
}

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

/**
 * Helper method to have the sync adapter sync immediately
 *
 * @param context The context used to access the account service
 *///from w  w w . ja va 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.sync_provider_authority),
            bundle);
}