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(Account account, String authority, Bundle extras) 

Source Link

Document

Start an asynchronous sync operation.

Usage

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

/**
 * Helper method to have the sync adapter sync immediately
 *
 * @param context The context used to access the account service
 *///  w ww.  j  ava2  s  . c  o m
public static void syncImmediately(Context context) {
    //Log.d("Weather4USyncAdapter", "syncImmediately");
    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.activiti.android.platform.provider.transfer.ContentTransferManager.java

public static void startSaveAsTransfer(Activity activity, String contentId, String contentUri) {
    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_SAVE_AS);
    settingsBundle.putString(ContentTransferSyncAdapter.ARGUMENT_CONTENT_URI, contentUri);
    settingsBundle.putString(ContentTransferSyncAdapter.ARGUMENT_CONTENT_ID, contentId);
    ContentResolver.requestSync(ActivitiAccountManager.getInstance(activity).getCurrentAndroidAccount(),
            ContentTransferProvider.AUTHORITY, settingsBundle);
}

From source file:de.spiritcroc.syncsettings.Util.java

public static void syncNow(Account account, String authority) {
    Bundle extras = new Bundle();
    ContentResolver.requestSync(account, authority, extras);
}

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

/**
 * Requests a manual sync to the system.
 * @return true if the sync has been actually requested to the system.
 *///from   w w w.j  a  va  2s.c  o  m
public static boolean requestSync(Context context, boolean force) {
    if (!force && isThrottling()) {
        Log.d(TAG, "not requesting sync - throttling");
        return false;
    }

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

    Account acc = Authenticator.getDefaultAccount(context);
    Bundle extra = new Bundle();
    // override auto-sync and background data settings
    extra.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    // put our sync ahead of other sync operations :)
    extra.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    ContentResolver.requestSync(acc, ContactsContract.AUTHORITY, extra);
    return true;
}

From source file:de.spiritcroc.syncsettings.Util.java

public static void forceSyncNow(Account account, String authority) {
    Bundle extras = new Bundle();
    extras.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, true);
    ContentResolver.requestSync(account, authority, extras);
}

From source file:io.github.hidroh.materialistic.data.SyncDelegate.java

@UiThread
public static void scheduleSync(Context context, Job job) {
    if (!Preferences.Offline.isEnabled(context)) {
        return;// w  w w.  j  ava 2s .c  om
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !TextUtils.isEmpty(job.id)) {
        JobInfo.Builder builder = new JobInfo.Builder(Long.valueOf(job.id).intValue(),
                new ComponentName(context.getPackageName(), ItemSyncJobService.class.getName()))
                        .setRequiredNetworkType(
                                Preferences.Offline.isWifiOnly(context) ? JobInfo.NETWORK_TYPE_UNMETERED
                                        : JobInfo.NETWORK_TYPE_ANY)
                        .setExtras(job.toPersistableBundle());
        if (Preferences.Offline.currentConnectionEnabled(context)) {
            builder.setOverrideDeadline(0);
        }
        ((JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(builder.build());
    } else {
        Bundle extras = new Bundle(job.toBundle());
        extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        Account syncAccount;
        AccountManager accountManager = AccountManager.get(context);
        Account[] accounts = accountManager.getAccountsByType(BuildConfig.APPLICATION_ID);
        if (accounts.length == 0) {
            syncAccount = new Account(SYNC_ACCOUNT_NAME, BuildConfig.APPLICATION_ID);
            accountManager.addAccountExplicitly(syncAccount, null, null);
        } else {
            syncAccount = accounts[0];
        }
        ContentResolver.requestSync(syncAccount, MaterialisticProvider.PROVIDER_AUTHORITY, extras);
    }
}

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

/**
 *  Sync the remote data immediately passing along sync data to
 *  the routines to determine how much data to sync
 *
 * @param context Activity context//from  w  ww.  j  ava2s  .com
 * @param syncAll if true process all news items within the date range,
 *                if false process normally by checking the timestamps
 * @param syncMax Max number of news items to process
 */
public static void syncImmediately(Context context, boolean syncAll, int syncMax) {
    Bundle bundle = new Bundle();
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    bundle.putBoolean(SYNC_EXTRAS_SYNC_ALL, syncAll);
    bundle.putInt(SYNC_EXTRAS_SYNC_MAX, syncMax);
    ContentResolver.requestSync(getSyncAccount(context), context.getString(R.string.content_authority), bundle);
}

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

public static void startShare(Activity activity, String contentId, String filepath, String mimetype) {
    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_SHARE);
    settingsBundle.putString(ContentTransferSyncAdapter.ARGUMENT_FILE_PATH, filepath);
    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.UserGroupsSyncService.java

/**
 * Perform sync./* w w w .jav a  2 s  . co m*/
 * 
 * @param context
 *            the context
 * @param account
 *            the account
 * @param extras
 *            the extras
 * @param authority
 *            the authority
 * @param provider
 *            the provider
 * @param syncResult
 *            the sync result
 */
public void performSync(Context context, Account account, Bundle extras, String authority,
        ContentProviderClient provider, SyncResult syncResult) {
    // TODO Auto-generated method stub
    try {
        UserGroupsDb usergroups = new UserGroupsDb(context);
        Intent intent = new Intent();
        intent.setAction(SyncFinishReceiver.SYNC_FINISH);
        if (OpenERPServerConnection.isNetworkAvailable(context)) {
            Log.i(TAG + "::performSync()", "Sync with Server Started");
            OEHelper oe = usergroups.getOEInstance();
            if (oe.syncWithServer(usergroups, null, false, false)) {
                MailFollowerDb group_follower = new MailFollowerDb(context);
                OEHelper oe_1 = group_follower.getOEInstance();
                JSONObject domain = new JSONObject();
                int partner_id = Integer.parseInt(OpenERPAccountManager.currentUser(context).getPartner_id());
                domain.accumulate("domain", new JSONArray("[[\"partner_id\", \"=\", " + partner_id
                        + "],[\"res_model\",\"=\", \"" + usergroups.getModelName() + "\"]]"));

                if (oe_1.syncWithServer(group_follower, domain, false, false)) {
                    Log.i(TAG, "UserGroups Sync Finished");
                    MailFollowerDb follower = new MailFollowerDb(context);
                    List<HashMap<String, Object>> user_groups = follower.executeSQL(follower.getModelName(),
                            new String[] { "res_id" },
                            new String[] { "partner_id = ?", "AND", "res_model = ?" },
                            new String[] { partner_id + "", "mail.group" });
                    JSONArray group_ids = new JSONArray();
                    if (user_groups.size() > 0) {
                        for (HashMap<String, Object> row : user_groups) {
                            group_ids.put(Integer.parseInt(row.get("res_id").toString()));
                        }
                    }
                    context.sendBroadcast(intent);
                    Bundle bundle = new Bundle();
                    bundle.putString("group_ids", group_ids.toString());
                    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
                    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
                    ContentResolver.requestSync(account, MessageProvider.AUTHORITY, bundle);
                }

            }

        } else {
            Log.e("OpenERPServerConnection", "Unable to Connect with server");
        }

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

}

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

/**
 * Instructs the sync adapter to sync immediately.
 *//*from w  w w . j a  va  2  s . c  o  m*/
public static void syncImmediately(Context context) {
    Log.d(LOG_TAG, context.getString(R.string.log_sync_immediately));

    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);
}