Java Code Examples for android.content.ContentResolver#requestSync()
The following examples show how to use
android.content.ContentResolver#requestSync() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContinueReceiver.java From haxsync with GNU General Public License v2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { SharedPreferences prefs = context.getSharedPreferences(context.getPackageName() + "_preferences", Context.MODE_MULTI_PROCESS); boolean wifiOnly = prefs.getBoolean("wifi_only", false); boolean chargingOnly = prefs.getBoolean("charging_only", false); String action = intent.getAction(); if((wifiOnly && DeviceUtil.isWifi(context) && action.equals("android.net.wifi.STATE_CHANGE")) || (chargingOnly && action.equals("android.intent.action.ACTION_POWER_CONNECTED"))){ AccountManager am = AccountManager.get(context); Account[] accs = am.getAccountsByType(context.getString(R.string.ACCOUNT_TYPE)); if (accs.length > 0){ Account account = accs[0]; SharedPreferences.Editor editor = prefs.edit(); if (prefs.getBoolean("missed_contact_sync", false)){ ContentResolver.requestSync(account, ContactsContract.AUTHORITY, new Bundle()); editor.putBoolean("missed_contact_sync", false); } if (prefs.getBoolean("missed_calendar_sync", false)){ ContentResolver.requestSync(account, CalendarContract.AUTHORITY, new Bundle()); editor.putBoolean("missed_calendar_sync", false); } editor.commit(); } } }
Example 2
Source File: SunshineSyncAdapter.java From Advanced_Android_Development with Apache License 2.0 | 6 votes |
/** * Helper method to schedule the sync adapter periodic execution */ public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // we can enable inexact timers in our periodic sync SyncRequest request = new SyncRequest.Builder(). syncPeriodic(syncInterval, flexTime). setSyncAdapter(account, authority). setExtras(new Bundle()).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
Example 3
Source File: MainActivity.java From SyncManagerAndroid-DemoGoogleTasks with MIT License | 6 votes |
private void initiateSync() { Log.d(TAG, "initiateSync... google account:"+ mGoogleAccountName); Account account = getGoogleAccount(mGoogleAccountName); if (account != null) { Log.d(TAG, "Found account! init sync..."); // 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(account, TaskSyncContentProvider.AUTHORITY, settingsBundle); } }
Example 4
Source File: SyncAdapter.java From Paperwork-Android with MIT License | 6 votes |
public static void syncImmediately(Context context, SwipeRefreshLayout refreshLayout) { sSwipeContainer = refreshLayout; if (!isNetworkAvailable(context)) { setSwipeRefreshing(false); Log.d(LOG_TAG, "No internet available"); return; } Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync(getSyncAccount(context), DatabaseContract.CONTENT_AUTHORITY, bundle); }
Example 5
Source File: SunshineSyncAdapter.java From Krishi-Seva with MIT License | 6 votes |
/** * Helper method to schedule the sync adapter periodic execution */ public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // we can enable inexact timers in our periodic sync SyncRequest request = new SyncRequest.Builder(). syncPeriodic(syncInterval, flexTime). setSyncAdapter(account, authority). setExtras(new Bundle()).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
Example 6
Source File: AccountManagerHelper.java From moVirt with Apache License 2.0 | 6 votes |
/** * Helper method to trigger an immediate sync ("refreshAccounts"). * <p> * <p>This should only be used when we need to preempt the normal sync schedule. Typically, this * means the user has pressed the "refreshAccounts" button. * <p> * Note that SYNC_EXTRAS_MANUAL will cause an immediate sync, without any optimization to * preserve battery life. If you know new data is available (perhaps via a GCM notification), * but the user is not actively waiting for that data, you should omit this flag; this will give * the OS additional freedom in scheduling your sync request. */ public void triggerRefresh(MovirtAccount account) { Account acc = account.getAccount(); 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); // cancel sync because account will not sync if similar sync is already in progress if (ContentResolver.isSyncPending(acc, OVirtContract.CONTENT_AUTHORITY) || ContentResolver.isSyncActive(acc, OVirtContract.CONTENT_AUTHORITY)) { ContentResolver.cancelSync(acc, OVirtContract.CONTENT_AUTHORITY); } ContentResolver.requestSync(acc, OVirtContract.CONTENT_AUTHORITY, b); }
Example 7
Source File: SunshineSyncAdapter.java From Advanced_Android_Development with Apache License 2.0 | 5 votes |
/** * Helper method to have the sync adapter sync immediately * @param context The context used to access the account service */ 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); }
Example 8
Source File: SyncAdapter.java From Paperwork-Android with MIT License | 5 votes |
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), DatabaseContract.CONTENT_AUTHORITY, bundle); }
Example 9
Source File: SyncStorageEngine.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void requestSync(AuthorityInfo authorityInfo, int reason, Bundle extras, @SyncExemption int syncExemptionFlag) { if (android.os.Process.myUid() == android.os.Process.SYSTEM_UID && mSyncRequestListener != null) { mSyncRequestListener.onSyncRequest(authorityInfo.target, reason, extras, syncExemptionFlag); } else { SyncRequest.Builder req = new SyncRequest.Builder() .syncOnce() .setExtras(extras); req.setSyncAdapter(authorityInfo.target.account, authorityInfo.target.provider); ContentResolver.requestSync(req.build()); } }
Example 10
Source File: EvercamAccount.java From evercam-android with GNU Affero General Public License v3.0 | 5 votes |
private void startSync(Account account) { final int SYNC_INTERVAL = 3600 * 6; final String AUTHORITY = mContext.getString(R.string.content_provider_authorities); //Force request a sync and also enable the auto sync Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); ContentResolver.requestSync(account, AUTHORITY, bundle); ContentResolver.setSyncAutomatically(account, AUTHORITY, true); ContentResolver.addPeriodicSync(account, AUTHORITY, Bundle.EMPTY, SYNC_INTERVAL); }
Example 11
Source File: WoodminSyncAdapter.java From Woodmin with Apache License 2.0 | 5 votes |
public static void syncImmediately(final 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); }
Example 12
Source File: LayersFragment.java From android_gisapp with GNU General Public License v3.0 | 5 votes |
@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); } updateInfo(); break; case R.id.new_layer: if (getActivity() != null) { // View view = getActivity().getWindow().getDecorView().findViewById(android.R.id.content); View view = getActivity().findViewById(R.id.new_layer); PopupMenu popup = new PopupMenu(getActivity(), view); UiUtil.setForceShowIcon(popup); popup.getMenuInflater().inflate(R.menu.add_layer, popup.getMenu()); popup.setOnMenuItemClickListener(this); if (!AccountUtil.isProUser(getActivity())) { popup.getMenu().findItem(R.id.menu_add_ngw).setIcon(R.drawable.ic_lock_black_24dp); } popup.show(); } break; } }
Example 13
Source File: ItemsContentProvider.java From android-galaxyzoo with GNU General Public License v3.0 | 5 votes |
/** Ask the SyncAdapter to do its work. * We call this when we think it's likely that some work is necessary. */ private static void requestSync() { final Bundle extras = new Bundle(); extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); //Ask the framework to run our SyncAdapter. //We call this far too often, //but we trust the SyncAdapter system to not actually do the sync too often. //That seems to work fine as long as the SyncAdapter is in its own process. //See android:process=":sync" in AndroidManifest.xml ContentResolver.requestSync(null, Item.AUTHORITY, extras); }
Example 14
Source File: InvalidationService.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * Calls {@link ContentResolver#requestSync(Account, String, Bundle)} to trigger a sync. Split * into a separate method so that it can be overriden in tests. */ @VisibleForTesting void requestSyncFromContentResolver( Bundle bundle, Account account, String contractAuthority) { Log.d(TAG, "Request sync: " + account + " / " + contractAuthority + " / " + bundle.keySet()); ContentResolver.requestSync(account, contractAuthority, bundle); }
Example 15
Source File: SyncUtils.java From ChannelSurfer with MIT License | 5 votes |
public static void requestSync(Context mContext, String inputId) { inputId = inputId==null?"":inputId; Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); bundle.putString(SyncAdapter.BUNDLE_KEY_INPUT_ID, inputId); Log.d(TAG, "Request sync"); ContentResolver.requestSync(DummyAccountService.getAccount(mContext), CONTENT_AUTHORITY, bundle); }
Example 16
Source File: SyncUtils.java From hr with GNU Affero General Public License v3.0 | 5 votes |
public void requestSync(String authority, Bundle bundle) { Account account = mUser.getAccount(); 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); }
Example 17
Source File: SyncStorageEngine.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void requestSync(Account account, int userId, int reason, String authority, Bundle extras, @SyncExemption int syncExemptionFlag) { // If this is happening in the system process, then call the syncrequest listener // to make a request back to the SyncManager directly. // If this is probably a test instance, then call back through the ContentResolver // which will know which userId to apply based on the Binder id. if (android.os.Process.myUid() == android.os.Process.SYSTEM_UID && mSyncRequestListener != null) { mSyncRequestListener.onSyncRequest( new EndPoint(account, authority, userId), reason, extras, syncExemptionFlag); } else { ContentResolver.requestSync(account, authority, extras); } }
Example 18
Source File: Accounts.java From cathode with Apache License 2.0 | 4 votes |
public static void requestCalendarSync(Context context) { Account account = getAccount(context); ContentResolver.requestSync(account, BuildConfig.AUTHORITY_DUMMY_CALENDAR, new Bundle()); }
Example 19
Source File: DataSynchronizer.java From PhilHackerNews with MIT License | 4 votes |
public void requestCommentsSync(Item item, int limit) { Bundle settingsBundle = makeExpeditedManualSyncSettingsBundle(); settingsBundle.putInt(HackerNewsSyncAdapter.EXTRA_STORY, item.getId()); settingsBundle.putInt(HackerNewsSyncAdapter.EXTRA_KEY_LIMIT, limit); ContentResolver.requestSync(mAccount, HackerNewsData.CONTENT_AUTHORITY, settingsBundle); }
Example 20
Source File: SyncUtils.java From android-BasicSyncAdapter with Apache License 2.0 | 3 votes |
/** * Helper method to trigger an immediate sync ("refresh"). * * <p>This should only be used when we need to preempt the normal sync schedule. Typically, this * means the user has pressed the "refresh" button. * * Note that SYNC_EXTRAS_MANUAL will cause an immediate sync, without any optimization to * preserve battery life. If you know new data is available (perhaps via a GCM notification), * but the user is not actively waiting for that data, you should omit this flag; this will give * the OS additional freedom in scheduling your sync request. */ public static void TriggerRefresh() { 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); ContentResolver.requestSync( GenericAccountService.GetAccount(ACCOUNT_TYPE), // Sync account FeedContract.CONTENT_AUTHORITY, // Content authority b); // Extras }