List of usage examples for android.content ContentResolver requestSync
public static void requestSync(Account account, String authority, Bundle extras)
From source file:com.activiti.android.app.fragments.labs.LabsMenuFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Button sync = (Button) viewById(R.id.app_sync); sync.setOnClickListener(new View.OnClickListener() { @Override/*from w w w. j av a2 s . co m*/ public void onClick(View v) { List<Account> accounts = ActivitiAccountManager.getInstance(getActivity()).getAndroidAccounts(); Bundle settingsBundle = new Bundle(); settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); ContentResolver.requestSync(accounts.get(0), ProcessDefinitionModelProvider.AUTHORITY, settingsBundle); } }); }
From source file:edu.mit.mobile.android.locast.sync.LocastSyncService.java
/** * Convenience method to request a sync. * * This wraps {@link ContentResolver#requestSync(Account, String, Bundle)} * and fills in the necessary extras.//from w w w . j av a2s.c om * * @param account * @param what the uri of the item that needs to be sync'd. can be null * @param explicitSync * if true, adds {@link ContentResolver#SYNC_EXTRAS_MANUAL} to * the extras * @param extras */ public static void startSync(Account account, Uri what, Bundle extras) { if (what != null) { extras.putString(LocastSyncService.EXTRA_SYNC_URI, what.toString()); } if (extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false)) { if (SYNC_ADAPTER != null) { if (DEBUG) { Log.d(TAG, "canceling current sync to make room for expedited sync of " + what); } // only cancel the ongoing sync, to leave the queue untouched. SYNC_ADAPTER.cancelCurrentSync(); } } if (DEBUG) { Log.d(TAG, "requesting sync for " + account + " with extras: " + extras); } ContentResolver.requestSync(account, MediaProvider.AUTHORITY, extras); }
From source file:dev.drsoran.moloko.sync.util.SyncUtils.java
public final static void requestScheduledSync(Account account) { final Bundle bundle = new Bundle(); bundle.putBoolean(Constants.SYNC_EXTRAS_SCHEDULED, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, true); ContentResolver.requestSync(account, Rtm.AUTHORITY, bundle); }
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 w w w . j av a 2 s.com*/ 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:edu.mit.mobile.android.locast.sync.AbsLocastAccountSyncService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Bundle extras = intent.getExtras();// ww w . j av a 2 s . c om if (extras == null) { extras = new Bundle(); } extras.putString(EXTRA_SYNC_URI, intent.getData().toString()); final Account account = extras.getParcelable(EXTRA_ACCOUNT); // TODO make this shortcut the Android sync system. ContentResolver.requestSync(account, getAuthority(), extras); return START_NOT_STICKY; }
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: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 ww w .j a va 2 s . 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 . j ava2 s. c o 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: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 ww . ja v a 2s . com 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();//w w w . j a v a 2 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); }