Java Code Examples for android.content.ContentResolver#getSyncAutomatically()

The following examples show how to use android.content.ContentResolver#getSyncAutomatically() . 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: AccountSnippet.java    From mobly-bundled-snippets with Apache License 2.0 6 votes vote down vote up
/**
 * Updates ContentResolver sync settings for an Account's specified SyncAdapter.
 *
 * <p>Sets an accounts SyncAdapter (selected based on authority) to sync/not-sync automatically
 * and immediately requests/cancels a sync.
 *
 * <p>updateSync should always be called under {@link AccountSnippet#mLock} write lock to avoid
 * flapping between the getSyncAutomatically and setSyncAutomatically calls.
 *
 * @param account A Google Account.
 * @param authority The authority of a content provider that should (not) be synced.
 * @param sync Whether or not the account's content provider should be synced.
 */
private void updateSync(Account account, String authority, boolean sync) {
    if (ContentResolver.getSyncAutomatically(account, authority) != sync) {
        ContentResolver.setSyncAutomatically(account, authority, sync);
        if (sync) {
            ContentResolver.requestSync(account, authority, new Bundle());
        } else {
            ContentResolver.cancelSync(account, authority);
        }
        Log.i(
                "Set sync to "
                        + sync
                        + " for account "
                        + account
                        + ", adapter "
                        + authority
                        + ".");
    }
}
 
Example 2
Source File: SyncHelper.java    From narrate-android with Apache License 2.0 6 votes vote down vote up
public static void requestManualSync(Account mChosenAccount, Bundle extras) {
    if (mChosenAccount != null &&
            ContentResolver.getSyncAutomatically(User.getAccount(), Contract.AUTHORITY)) {

        LogUtil.log(TAG, "Requesting manual sync for account " + mChosenAccount.name);

        Bundle b = new Bundle(extras);
        b.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        b.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);

        cancelPendingActiveSync(mChosenAccount);

        LogUtil.log(TAG, "Requesting sync now.");
        ContentResolver.requestSync(mChosenAccount, Contract.AUTHORITY, b);
    } else {
        LogUtil.log(TAG, "Can't request manual sync -- no chosen account.");
    }
}
 
Example 3
Source File: WizardActivity.java    From haxsync with GNU General Public License v2.0 6 votes vote down vote up
private void readSettings(){
  	Account account = DeviceUtil.getAccount(this);
  	boolean contactSync = true;
  	boolean calendarSync = true;
  	if (account != null){
   	contactSync = ContentResolver.getSyncAutomatically(account, ContactsContract.AUTHORITY);
   	calendarSync = ContentResolver.getSyncAutomatically(account, CalendarContract.AUTHORITY);
  	}
SharedPreferences prefs = getSharedPreferences(getPackageName() + "_preferences", MODE_MULTI_PROCESS);

  	if (!contactSync)
  		contactSpinner.setSelection(0);
  	else if (prefs.getBoolean("phone_only", true))
  		contactSpinner.setSelection(1);
  	else
  		contactSpinner.setSelection(2);
  	
eventSwitch.setChecked(prefs.getBoolean("sync_events", true) && calendarSync);
birthdaySwitch.setChecked(prefs.getBoolean("sync_birthdays", true) && calendarSync);
reminderSwitch.setChecked(prefs.getBoolean("event_reminders", true));
wizardCheck.setChecked(!DeviceUtil.isWizardShown(this));
toggleReminderVisibility();
  }
 
Example 4
Source File: DirectoryHelperV1.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static Optional<AccountHolder> getOrCreateAccount(Context context) {
  AccountManager accountManager = AccountManager.get(context);
  Account[]      accounts       = accountManager.getAccountsByType(context.getPackageName());

  Optional<AccountHolder> account;

  if (accounts.length == 0) account = createAccount(context);
  else                      account = Optional.of(new AccountHolder(accounts[0], false));

  if (account.isPresent() && !ContentResolver.getSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY)) {
    ContentResolver.setSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY, true);
  }

  return account;
}
 
Example 5
Source File: SystemSyncContentResolverDelegate.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public boolean getSyncAutomatically(Account account, String authority) {
    return ContentResolver.getSyncAutomatically(account, authority);
}
 
Example 6
Source File: NGWSettingsFragment.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static boolean isAccountSyncEnabled(
        Account account,
        String authority)
{
    return null != account && ContentResolver.getSyncAutomatically(account, authority);
}
 
Example 7
Source File: SyncAdapterHelper.java    From COCOFramework with Apache License 2.0 4 votes vote down vote up
public boolean isAutoSync(Account mAccount) {
    return ContentResolver.getIsSyncable(mAccount, AUTHORITY) > 0 && ContentResolver.getMasterSyncAutomatically() && ContentResolver.getSyncAutomatically(mAccount, AUTHORITY);
}
 
Example 8
Source File: AccountManagerHelper.java    From moVirt with Apache License 2.0 4 votes vote down vote up
public boolean isPeriodicSyncable(MovirtAccount account) throws AccountDeletedException {
    return account != null && ContentResolver.getSyncAutomatically(account.getAccount(), OVirtContract.CONTENT_AUTHORITY);
}
 
Example 9
Source File: SystemSyncContentResolverDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public boolean getSyncAutomatically(Account account, String authority) {
    return ContentResolver.getSyncAutomatically(account, authority);
}
 
Example 10
Source File: SystemSyncContentResolverDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public boolean getSyncAutomatically(Account account, String authority) {
    return ContentResolver.getSyncAutomatically(account, authority);
}