Example usage for android.content ContentResolver getPeriodicSyncs

List of usage examples for android.content ContentResolver getPeriodicSyncs

Introduction

In this page you can find the example usage for android.content ContentResolver getPeriodicSyncs.

Prototype

public static List<PeriodicSync> getPeriodicSyncs(Account account, String authority) 

Source Link

Document

Get the list of information about the periodic syncs for the given account and authority.

Usage

From source file:org.andstatus.app.account.AccountData.java

private static long getSyncFrequencySeconds(Account account) {
    long syncFrequencySeconds = 0;
    List<PeriodicSync> syncs = ContentResolver.getPeriodicSyncs(account, MyProvider.AUTHORITY);
    if (!syncs.isEmpty()) {
        syncFrequencySeconds = syncs.get(0).period;
    }/*from   w w w  .  j a v a  2  s  .  c  o m*/
    return syncFrequencySeconds;
}

From source file:com.ntsync.android.sync.activities.AccountStatisticListLoader.java

@Override
public List<AccountStatistic> loadInBackground() {
    Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE);

    List<AccountStatistic> statList = new ArrayList<AccountStatistic>();
    for (Account account : accounts) {

        String username = account.name;
        int contactCount = -1;
        int contactGroupCount = -1;
        Context ctx = getContext();

        AccountSyncResult syncResult = SyncUtils.getSyncResult(accountManager, account);
        Date lastSync = syncResult != null ? syncResult.getLastSyncTime() : null;
        Date nextSync = null;//from  w  w w.  j a va  2 s.  c o  m

        boolean autoSyncEnabled = ContentResolver.getMasterSyncAutomatically()
                && ContentResolver.getSyncAutomatically(account, ContactsContract.AUTHORITY);
        if (autoSyncEnabled) {
            List<PeriodicSync> syncs = ContentResolver.getPeriodicSyncs(account, ContactsContract.AUTHORITY);
            long nextSyncRef = lastSync != null ? lastSync.getTime() : System.currentTimeMillis();
            for (PeriodicSync sync : syncs) {
                long nextTime = nextSyncRef + sync.period * 1000;
                if (nextSync == null || nextTime < nextSync.getTime()) {
                    nextSync = new Date(nextTime);
                }
            }
        }

        boolean autoSync = ContentResolver.getSyncAutomatically(account, ContactsContract.AUTHORITY);

        // Get Restrictions
        Restrictions restr = SyncUtils.getRestrictions(account, accountManager);
        if (restr == null) {
            try {
                String authtoken = NetworkUtilities.blockingGetAuthToken(accountManager, account, null);
                restr = NetworkUtilities.getRestrictions(getContext(), account, authtoken, accountManager);
            } catch (OperationCanceledException e) {
                Log.i(TAG, "Restriction loading canceled from user", e);
            } catch (AuthenticatorException e) {
                Log.w(TAG, "Authenticator failed", e);
            } catch (AuthenticationException e) {
                Log.i(TAG, "Authentification failed", e);
            } catch (NetworkErrorException e) {
                Log.i(TAG, "Loading Restrictions failed", e);
            } catch (ServerException e) {
                Log.i(TAG, "Loading Restrictions failed", e);
            }
        }

        contactCount = ContactManager.getContactCount(ctx, account);
        contactGroupCount = ContactManager.getContactGroupCount(ctx, account);

        statList.add(new AccountStatistic(username, contactCount, contactGroupCount, restr, syncResult,
                nextSync, autoSync));

    }
    return statList;
}

From source file:com.granita.contacticloudsync.syncadapter.AccountSettings.java

public Long getSyncInterval(String authority) {
    if (ContentResolver.getIsSyncable(account, authority) <= 0)
        return null;

    if (ContentResolver.getSyncAutomatically(account, authority)) {
        List<PeriodicSync> syncs = ContentResolver.getPeriodicSyncs(account, authority);
        if (syncs.isEmpty())
            return SYNC_INTERVAL_MANUALLY;
        else//from  www.j av a 2  s  . co  m
            return syncs.get(0).period;
    } else
        return SYNC_INTERVAL_MANUALLY;
}

From source file:at.bitfire.davdroid.AccountSettings.java

public Long getSyncInterval(@NonNull String authority) {
    if (ContentResolver.getIsSyncable(account, authority) <= 0)
        return null;

    if (ContentResolver.getSyncAutomatically(account, authority)) {
        List<PeriodicSync> syncs = ContentResolver.getPeriodicSyncs(account, authority);
        if (syncs.isEmpty())
            return SYNC_INTERVAL_MANUALLY;
        else/* w  ww .j a  va2 s .  c  om*/
            return syncs.get(0).period;
    } else
        return SYNC_INTERVAL_MANUALLY;
}

From source file:com.ntsync.android.sync.shared.SyncUtils.java

/**
 * Create a new Account and activate the automatic sync
 * //from   w w w.j  a v  a  2 s.c  om
 * @param account
 *            null is not allowed
 * @param accountManager
 *            null is not allowed
 * @param password
 *            null is not allowed
 */
public static boolean createAccount(Context context, final Account account, AccountManager accountManager,
        String password) {
    boolean added = accountManager.addAccountExplicitly(account, password, null);
    if (added) {
        List<PeriodicSync> syncs = ContentResolver.getPeriodicSyncs(account, ContactsContract.AUTHORITY);
        if (syncs != null) {
            // Remove default syncs.
            for (PeriodicSync periodicSync : syncs) {
                ContentResolver.removePeriodicSync(account, ContactsContract.AUTHORITY, periodicSync.extras);
            }
        }
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
        int synctime;
        try {
            synctime = settings.getInt("pref_synctime", DEFAULT_SYNCINTERVAL);
        } catch (ClassCastException e) {
            LogHelper.logI(TAG, "Invalid SyncTime-Settingvalue", e);
            synctime = DEFAULT_SYNCINTERVAL;
        }
        if (synctime != 0) {
            addPeriodicSync(ContactsContract.AUTHORITY, Bundle.EMPTY, synctime, context);
        }

        // Set contacts sync for this account.
        ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
    } else {
        LogHelper.logI(TAG, "Account " + account.name + " is already available.");
    }
    return added;
}