List of usage examples for android.content ContentResolver requestSync
public static void requestSync(Account account, String authority, Bundle extras)
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.// w w w .ja va2s . 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:com.clearcenter.mobile_demo.mdAuthenticatorActivity.java
private void finishLogin(String authToken) { Log.i(TAG, "finishLogin()"); final Account account = new Account(nickname, mdConstants.ACCOUNT_TYPE); if (request_new_account) { account_manager.addAccountExplicitly(account, authToken, null); account_manager.setUserData(account, "hostname", hostname); account_manager.setUserData(account, "username", username); // Set system info sync for this account. final Bundle extras = new Bundle(); ContentResolver.setSyncAutomatically(account, mdContentProvider.AUTHORITY, true); if (android.os.Build.VERSION.SDK_INT >= 8) { ContentResolver.addPeriodicSync(account, mdContentProvider.AUTHORITY, extras, 10); }//from ww w . ja v a2s . co m } else account_manager.setPassword(account, authToken); final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, nickname); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, mdConstants.ACCOUNT_TYPE); setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); ContentResolver.requestSync(account, mdContentProvider.AUTHORITY, new Bundle()); finish(); }
From source file:com.ntsync.android.sync.activities.ShopActivity.java
private void onPaymentSuccess(Account account) { MessageDialog.showAndClose(R.string.shop_activity_paymentsuccess, this); // Perform sync Bundle extras = new Bundle(); extras.putBoolean(Constants.PARAM_GETRESTRICTIONS, true); ContentResolver.requestSync(account, Constants.CONTACT_AUTHORITY, extras); }
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( new Account(AccountUtils.getChosenAccountName(this), GoogleAccountManager.ACCOUNT_TYPE), ScheduleContract.CONTENT_AUTHORITY, extras); }//from www. ja v a 2s.com if (mSocialStreamFragment != null) { mSocialStreamFragment.refresh(); } }
From source file:es.ugr.swad.swadroid.modules.notifications.Notifications.java
@Override protected void requestService() throws Exception { int numDeletedNotif = 0; if (SyncUtils.isSyncAutomatically(getApplicationContext())) { Log.i(TAG, "Automatic synchronization is enabled. Requesting asynchronous sync operation"); // Call synchronization service ContentResolver.requestSync(account, authority, new Bundle()); } else {// www.j av a2 s . c om Log.i(TAG, "Automatic synchronization is disabled. Requesting manual sync operation"); // Calculates next timestamp to be requested Long timestamp = Long.valueOf(dbHelper.getFieldOfLastNotification("eventTime")); timestamp++; // Creates webservice request, adds required params and sends // request to webservice createRequest(SOAPClient.CLIENT_TYPE); addParam("wsKey", Login.getLoggedUser().getWsKey()); addParam("beginTime", timestamp); sendRequest(SWADNotification.class, false); if (result != null) { dbHelper.beginTransaction(); // Stores notifications data returned by webservice response ArrayList<?> res = new ArrayList<Object>((Vector<?>) result); SoapObject soap = (SoapObject) res.get(1); int numNotif = soap.getPropertyCount(); notifCount = 0; for (int i = 0; i < numNotif; i++) { SoapObject pii = (SoapObject) soap.getProperty(i); Long notifCode = Long.valueOf(pii.getProperty("notifCode").toString()); Long eventCode = Long.valueOf(pii.getProperty("eventCode").toString()); String eventType = pii.getProperty("eventType").toString(); Long eventTime = Long.valueOf(pii.getProperty("eventTime").toString()); String userSurname1 = pii.getProperty("userSurname1").toString(); String userSurname2 = pii.getProperty("userSurname2").toString(); String userFirstName = pii.getProperty("userFirstname").toString(); String userPhoto = pii.getProperty("userPhoto").toString(); String location = pii.getProperty("location").toString(); String summary = pii.getProperty("summary").toString(); Integer status = Integer.valueOf(pii.getProperty("status").toString()); String content = pii.getProperty("content").toString(); boolean notifReadSWAD = (status >= 4); boolean notifCancelled = (status >= 8); // Add not cancelled notifications only if (!notifCancelled) { SWADNotification n = new SWADNotification(notifCode, eventCode, eventType, eventTime, userSurname1, userSurname2, userFirstName, userPhoto, location, summary, status, content, notifReadSWAD, notifReadSWAD); dbHelper.insertNotification(n); // Count unread notifications only if (!notifReadSWAD) { notifCount++; } if (isDebuggable) Log.d(TAG, n.toString()); } } // Request finalized without errors setResult(RESULT_OK); Log.i(TAG, "Retrieved " + numNotif + " notifications (" + notifCount + " unread)"); // Clean old notifications to control database size numDeletedNotif = dbHelper.cleanOldNotificationsByAge(Constants.CLEAN_NOTIFICATIONS_THRESHOLD); Log.i(TAG, "Deleted " + numDeletedNotif + " notifications from database"); dbHelper.endTransaction(true); } } }
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); }/* ww w. j ava2 s .c o 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 ww w .j a v a2 s .c om*/ 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); }
From source file:com.oxplot.contactphotosync.AssignContactPhotoActivity.java
@SuppressWarnings("unchecked") @Override//from ww w. j av a2 s.co m public boolean onMenuItemSelected(int featureId, MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Intent upIntent = new Intent(this, SelectAccountActivity.class); if (NavUtils.shouldUpRecreateTask(this, upIntent)) { TaskStackBuilder.create(this).addNextIntent(upIntent).startActivities(); } else { NavUtils.navigateUpTo(this, upIntent); } return true; case R.id.menu_sync_now: // This is a convenient way of enabling and running the contact photo // sync. Account a = new Account(account, ACCOUNT_TYPE); ContentResolver.setSyncAutomatically(a, CONTACT_PHOTO_AUTHORITY, true); ContentResolver.requestSync(a, CONTACT_PHOTO_AUTHORITY, new Bundle()); Toast.makeText(this, getResources().getString(R.string.sync_requested), Toast.LENGTH_LONG).show(); break; case R.id.menu_download_all: case R.id.menu_upload_all: new DownloadUploadTask(item.getItemId() == R.id.menu_download_all ? DownloadUploadTask.TYPE_DOWNLOAD : DownloadUploadTask.TYPE_UPLOAD) .execute(((ContactAdapter) contactList.getAdapter()).getBackingList()); break; case R.id.menu_refresh: // XXX This is ugly and hackish. This of course doesn't stop us from being // lazy and using it here. onPause(); onResume(); break; } return super.onOptionsItemSelected(item); }
From source file:com.granita.tasks.TaskListFragment.java
/** * Trigger a synchronization for all accounts. *///w w w .j a v a2s. c om private void doSyncNow() { AccountManager accountManager = AccountManager.get(mAppContext); Account[] accounts = accountManager.getAccounts(); for (Account account : accounts) { // TODO: do we need a new bundle for each account or can we reuse it? Bundle extras = new Bundle(); extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync(account, mAuthority, extras); } }