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.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 {/*from ww w . j a va2  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
 *///from 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: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);/*from  w  ww.jav a2s  .  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 ww .ja v a 2s .c  o  m
    }

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

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

public static void syncImmediately(Context context) {
    Log.d(LOG_TAG, "syncImmediately: ");
    ConnectivityManager systemService = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = systemService.getActiveNetworkInfo();
    if (activeNetworkInfo == null) {
        new NoInternet().show(((MainActivity) context).getSupportFragmentManager(), "1");
    }/*w  w w  .  j  a  v  a 2  s  . co m*/
    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:de.azapps.mirakel.sync.taskwarrior.services.SyncAdapter.java

@Override
public void onPerformSync(final Account account, final Bundle extras, final String authority,
        final ContentProviderClient provider, final SyncResult syncResult) {
    // Do not sync if Mirakel is in demo mode
    if (MirakelCommonPreferences.isDemoMode()) {
        return;//w w w.  j  a va  2 s. c  o m
    }
    // Mostly it is annoying if there is a notification. So don't show it
    boolean showNotification = false;
    // But if the user actively clicks on "sync"  then show it.
    if (extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL)) {
        showNotification = true;
    }

    // Show notif
    try {
        showSyncNotification(showNotification);
    } catch (final ClassNotFoundException e) {
        Log.wtf(TAG, "no MainActivity found", e);
        return;
    }

    // get Sync Type
    String type = AccountManager.get(this.mContext).getUserData(account, BUNDLE_SERVER_TYPE);
    if (type == null) {
        type = TaskWarriorSync.TYPE;
    }
    boolean success = false;

    // Handle Error
    if (type.equals(TaskWarriorSync.TYPE)) {
        TW_ERRORS error = TW_ERRORS.NO_ERROR;
        try {
            final Optional<AccountMirakel> accountMirakel = AccountMirakel.get(account);
            if (accountMirakel.isPresent()) {
                final TaskWarriorAccount taskWarriorAccount = new TaskWarriorAccount(accountMirakel.get(),
                        getContext());
                new TaskWarriorSync(this.mContext).sync(taskWarriorAccount, false);
            }
        } catch (final TaskWarriorSyncFailedException e) {
            Log.e(TAG, "SyncError", e);
            error = e.getError();
        }
        success = setLastMessage(success, error);
    } else {
        Log.wtf(TAG, "Unknown SyncType");
    }
    this.mNotificationManager.cancel(SyncAdapter.NOTIFY_ID);
    try {
        handleError(showNotification, success);
    } catch (final ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}

From source file:jp.januaraid.android.synciteasy.gcm.GCMIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();/*from   w w  w .j  a v  a2  s. co  m*/
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that
         * GCM will be extended in the future with new message types, just
         * ignore any message types you're not interested in, or that you
         * don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            Log.i(Consts.TAG, "onHandleIntent: message error");
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Log.i(Consts.TAG, "onHandleIntent: message deleted");
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            String subId = intent.getStringExtra(GCM_KEY_SUBID);
            Log.i(Consts.TAG, "onHandleIntent: subId: " + subId);
            String[] tokens = subId.split(":");
            String typeId = tokens[1];

            // dispatch message
            if (GCM_TYPEID_QUERY.equals(typeId)) {
                Intent messageIntent = new Intent(BROADCAST_ON_MESSAGE);
                messageIntent.putExtras(intent);
                messageIntent.putExtra("token", tokens[2]);
                LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
                Log.i(Consts.TAG, ":sendBroadcast");
                // 
                String accountName = getApplicationContext()
                        .getSharedPreferences(Consts.PREF_KEY_CLOUD_BACKEND, Context.MODE_PRIVATE)
                        .getString(Consts.PREF_KEY_ACCOUNT_NAME, null);
                Account account = null;
                if (accountName == null) {
                    return;
                } else {
                    account = new Account(accountName, Consts.ACCOUNT_TYPE);
                }
                Bundle settingsBundle = new Bundle();
                settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
                settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
                settingsBundle.putString("token", tokens[2]);
                ContentResolver.requestSync(account, Consts.AUTHORITY, settingsBundle);
            }
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GCMBroadcastReceiver.completeWakefulIntent(intent);
}

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