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.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");
    }/*from  w w w .j  a va2 s. c om*/
    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:jp.januaraid.android.synciteasy.gcm.GCMIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();/*from   w ww . ja v a2  s  .  c  om*/
    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.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  w  w . j  a v a2s .c om
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:org.kontalk.sync.SyncAdapter.java

/**
 * Requests a manual sync to the system.
 * @return true if the sync has been actually requested to the system.
 *///w ww. jav  a 2s . co  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: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.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  ww w.  j  a v  a2  s  . c  om
 * @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.openerp.services.UserGroupsSyncService.java

/**
 * Perform sync.// w w  w  .j av  a2s. 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 v a  2 s  . com
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);
}

From source file:org.codarama.haxsync.activities.WelcomeActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.nav_home: {
        // Create fragment and give it an argument specifying the article it should show
        HomeFragment newFragment = new HomeFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the back stack so the user can navigate back
        transaction.replace(R.id.fragment_container, newFragment);
        transaction.addToBackStack(null);

        // Commit the transaction
        transaction.commit();//from w  w w  . ja v a 2 s .  c o  m
        return true;
    }

    case R.id.nav_settings: {
        Intent preferences = new Intent(getApplicationContext(), PreferencesActivity.class);
        startActivity(preferences);
        return true;
    }

    // as per https://developer.android.com/training/sync-adapters/running-sync-adapter.html
    // we might want to reconsider allowing manual sync - the basic flaw in this design is
    // that the user could not be trusted to know when it is the best time to sync
    case R.id.nav_manual_sync: {
        Log.d(TAG, "User requested manual sync");
        SyncAccount syncAccount = new SyncAccount(AccountManager.get(WelcomeActivity.this));
        Account account = syncAccount.getHaxSyncAccount(getResources().getString(R.string.ACCOUNT_TYPE));

        // Pass the settings flags by inserting them in a bundle
        Bundle settingsBundle = new Bundle();
        settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);

        ContentResolver.requestSync(account, "com.android.contacts", settingsBundle);
        ContentResolver.requestSync(account, "com.android.calendar", settingsBundle);
        return true;
    }

    default: {
        // If we got here, the user's action was not recognized.
        // Invoke the superclass to handle it.
        return super.onOptionsItemSelected(item);
    }
    }
}