List of usage examples for android.content ContentResolver requestSync
public static void requestSync(Account account, String authority, Bundle extras)
From source file:com.hybris.mobile.lib.commerce.provider.CatalogProvider.java
/** * Request a sync (we force it)/*from ww w .j a va 2 s .co m*/ * * @param bundle extras parameters for the sync */ private void requestSync(Bundle bundle) { if (bundle == null) { bundle = new Bundle(); } Log.i(TAG, "Requesting a sync with bundle: " + bundle.toString()); // Parameters to force the sync without any delay bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); ContentResolver.requestSync(account, authority, bundle); }
From source file:at.bitfire.davdroid.ui.AccountActivity.java
protected static void requestSync(Account account) { String authorities[] = { ContactsContract.AUTHORITY, CalendarContract.AUTHORITY, TaskProvider.ProviderName.OpenTasks.authority }; for (String authority : authorities) { Bundle extras = new Bundle(); extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); // manual sync extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); // run immediately (don't queue) ContentResolver.requestSync(account, authority, extras); }//ww w . ja v a 2 s. c om }
From source file:org.voidsink.anewjkuapp.utils.AppUtils.java
public static void triggerSync(Context context, Account account, boolean syncCalendar, boolean syncKusss) { try {/*from w w w.java 2s. com*/ if (context == null || account == null) { return; } if (syncCalendar || syncKusss) { Bundle b = new Bundle(); // Disable sync backoff and ignore sync preferences. In other // words...perform sync NOW! b.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); b.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); b.putBoolean(Consts.SYNC_SHOW_PROGRESS, true); if (syncCalendar) { ContentResolver.requestSync(account, // Sync CalendarContractWrapper.AUTHORITY(), // Calendar Content authority b); // Extras } if (syncKusss) { ContentResolver.requestSync(account, // Sync KusssContentContract.AUTHORITY, // KUSSS Content authority b); // Extras } } } catch (Exception e) { Analytics.sendException(context, e, true); } }
From source file:pt.up.mobile.syncadapter.SigarraSyncAdapter.java
private void syncProfiles(Account account, SyncResult syncResult) throws AuthenticationException, IOException, JSONException { final User user = AccountUtils.getUser(getContext(), account.name); final String profile; if (user.getType().equals(SifeupAPI.STUDENT_TYPE)) { profile = SifeupAPI.getReply(SifeupAPI.getStudenProfiletUrl(user.getUserCode()), account, getContext()); } else {//w ww.j a v a 2s. c o m profile = SifeupAPI.getReply(SifeupAPI.getEmployeeProfileUrl(user.getUserCode()), account, getContext()); } final String picPath = getProfilePic(user.getUserCode(), account, syncResult); final ContentValues values = new ContentValues(); values.put(SigarraContract.ProfileColumns.ID, user.getUserCode()); values.put(SigarraContract.ProfileColumns.CONTENT, profile); if (picPath != null) values.put(SigarraContract.ProfileColumns.PIC, picPath); values.put(BaseColumns.COLUMN_STATE, SyncStates.KEEP); getContext().getContentResolver().insert(SigarraContract.Profiles.CONTENT_URI, values); syncResult.stats.numEntries += 1; final Cursor c = getContext().getContentResolver().query(SigarraContract.Friends.CONTENT_URI, new String[] { SigarraContract.FriendsColumns.CODE_FRIEND, SigarraContract.FriendsColumns.TYPE_FRIEND }, SigarraContract.Friends.USER_FRIENDS, SigarraContract.Friends.getUserFriendsSelectionArgs(user.getUserCode()), null); try { if (c.moveToFirst()) { final ContentValues[] friends = new ContentValues[c.getCount()]; int i = 0; do { final ContentValues friendValues = new ContentValues(); final String friendCode = c .getString(c.getColumnIndex(SigarraContract.FriendsColumns.CODE_FRIEND)); final String friendPic = getProfilePic(friendCode, account, syncResult); friendValues.put(SigarraContract.ProfileColumns.ID, friendCode); final String friendType = c .getString(c.getColumnIndex(SigarraContract.FriendsColumns.TYPE_FRIEND)); final String friendPage; if (friendType.equals(SifeupAPI.STUDENT_TYPE)) { friendPage = SifeupAPI.getReply(SifeupAPI.getStudenProfiletUrl(friendCode), account, getContext()); } else { friendPage = SifeupAPI.getReply(SifeupAPI.getEmployeeProfileUrl(friendCode), account, getContext()); } friendValues.put(SigarraContract.ProfileColumns.CONTENT, friendPage); if (friendPic != null) friendValues.put(SigarraContract.ProfileColumns.PIC, friendPic); friendValues.put(BaseColumns.COLUMN_STATE, SyncStates.KEEP); friends[i++] = friendValues; } while (c.moveToNext()); getContext().getContentResolver().bulkInsert(SigarraContract.Profiles.CONTENT_URI, friends); syncResult.stats.numEntries += friends.length; } } finally { c.close(); } // Request sync for the contacts, if it is disabled in Settings // the sync won't be called ContentResolver.requestSync(account, ContactsContract.AUTHORITY, new Bundle()); }
From source file:com.owncloud.android.ui.activity.FileDisplayActivity.java
private void startSynchronization() { ContentResolver.cancelSync(null, AccountAuthenticator.AUTHORITY); // cancel // the // current // synchronizations // of // any // ownCloud // account Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync(getAccount(), AccountAuthenticator.AUTHORITY, bundle); shareDetailsSync();/*w ww. j a v a2 s. c o m*/ }
From source file:org.andstatus.app.account.MyAccount.java
public void requestSync() { if (isPersistent()) { ContentResolver.requestSync(getExisingAndroidAccount(), MyProvider.AUTHORITY, new Bundle()); } }
From source file:com.synox.android.ui.activity.FileActivity.java
protected void startSynchronization() { Log_OC.d(TAG, "Got to start sync"); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) { Log_OC.d(TAG, "Canceling all syncs for " + MainApp.getAuthority()); ContentResolver.cancelSync(null, MainApp.getAuthority()); // cancel the current synchronizations of any ownCloud account Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); Log_OC.d(TAG, "Requesting sync for " + getAccount().name + " at " + MainApp.getAuthority()); ContentResolver.requestSync(getAccount(), MainApp.getAuthority(), bundle); } else {/*from w w w . j a va 2 s . co m*/ Log_OC.d(TAG, "Requesting sync for " + getAccount().name + " at " + MainApp.getAuthority() + " with new API"); SyncRequest.Builder builder = new SyncRequest.Builder(); builder.setSyncAdapter(getAccount(), MainApp.getAuthority()); builder.setExpedited(true); builder.setManual(true); builder.syncOnce(); // Fix bug in Android Lollipop when you click on refresh the whole account Bundle extras = new Bundle(); builder.setExtras(extras); SyncRequest request = builder.build(); ContentResolver.requestSync(request); } }
From source file:com.glandorf1.joe.wsprnetviewer.app.sync.WsprNetViewerSyncAdapter.java
/** * Helper function to make the adapter sync now. * * @param context The application context *//*ww w. j a v a2 s . co m*/ public static void syncImmediately(Context context) { // 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); /* * Request the sync for the default account, authority, and manual sync settings */ ContentResolver.requestSync(getSyncAccount(context), context.getString(R.string.content_authority), settingsBundle); }
From source file:com.nononsenseapps.notepad.MainActivity.java
private void requestSync(String accountName) { if (accountName != null && !"".equals(accountName)) { Account account = SyncPrefs.getAccount(AccountManager.get(this), accountName); // Don't start a new sync if one is already going if (!ContentResolver.isSyncActive(account, NotePad.AUTHORITY)) { Bundle options = new Bundle(); // This will force a sync regardless of what the setting is // in accounts manager. Only use it here where the user has // manually desired a sync to happen NOW. options.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync(account, NotePad.AUTHORITY, options); }/* w w w . j a v a2 s . c o m*/ } }
From source file:de.azapps.mirakel.main_activity.MainActivity.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { if (this.mDrawerToggle.onOptionsItemSelected(item)) { return true; }/*from w w w .j ava2 s.co m*/ switch (item.getItemId()) { case R.id.menu_delete: handleDestroyTask(this.currentTask); updateShare(); return true; case R.id.menu_move: handleMoveTask(this.currentTask); return true; case R.id.list_delete: handleDestroyList(this.currentList); return true; case R.id.task_sorting: this.currentList = ListDialogHelpers.handleSortBy(this, this.currentList, new Helpers.ExecInterface() { @Override public void exec() { setCurrentList(MainActivity.this.currentList); } }, null); return true; case R.id.menu_new_list: getListFragment().editList(null); return true; case R.id.menu_sort_lists: final boolean t = !item.isChecked(); getListFragment().enableDrop(t); item.setChecked(t); return true; case R.id.menu_settings: final Intent intent = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(intent, MainActivity.RESULT_SETTINGS); break; case R.id.menu_contact: Helpers.contact(this); break; case R.id.menu_new_ui: MirakelCommonPreferences.setUseNewUI(true); Helpers.restartApp(this); break; case R.id.menu_sync_now: final Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); new Thread(new Runnable() { @SuppressLint("InlinedApi") @Override public void run() { final List<AccountMirakel> accounts = AccountMirakel.getEnabled(true); for (final AccountMirakel a : accounts) { // davdroid accounts should be there only from // API>=14... ContentResolver.requestSync(a.getAndroidAccount(), DefinitionsHelper.AUTHORITY_TYP, bundle); } } }).start(); break; case R.id.share_task: SharingHelper.share(this, getCurrentTask()); break; case R.id.share_list: SharingHelper.share(this, getCurrentList()); break; case R.id.search: onSearchRequested(); break; case R.id.menu_undo: UndoHistory.undoLast(this); updateCurrentListAndTask(); if (this.currentPosition == getTaskFragmentPosition()) { setCurrentTask(this.currentTask); } else if ((getListFragment() != null) && (getTasksFragment() != null) && (getListFragment().getAdapter() != null) && (getTasksFragment().getAdapter() != null)) { getListFragment().getAdapter().changeData(ListMirakel.all()); getListFragment().getAdapter().notifyDataSetChanged(); getTasksFragment().getAdapter().notifyDataSetChanged(); if (!MirakelCommonPreferences.isTablet() && (this.currentPosition == MainActivity.getTasksFragmentPosition())) { setCurrentList(getCurrentList()); } } break; case R.id.mark_as_subtask: TaskDialogHelpers.handleSubtask(this, this.currentTask, null, true); break; case R.id.menu_task_clone: try { final Task newTask = this.currentTask.create(); setCurrentTask(newTask, true); getListFragment().update(); updatesForTask(newTask); } catch (final NoSuchListException e) { Log.wtf(MainActivity.TAG, "List vanished on task cloning"); } break; default: return super.onOptionsItemSelected(item); } return true; }