Example usage for android.content ContentResolver SYNC_EXTRAS_ACCOUNT

List of usage examples for android.content ContentResolver SYNC_EXTRAS_ACCOUNT

Introduction

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

Prototype

String SYNC_EXTRAS_ACCOUNT

To view the source code for android.content ContentResolver SYNC_EXTRAS_ACCOUNT.

Click Source Link

Usage

From source file:com.android.providers.contacts.ContactsSyncAdapter.java

@Override
public void onSyncEnding(SyncContext context, boolean success) {
    final ContentResolver cr = getContext().getContentResolver();

    if (success && mPerformedGetServerDiffs && !mSyncCanceled) {
        Cursor cursor = cr.query(Photos.CONTENT_URI,
                new String[] { Photos._SYNC_ID, Photos._SYNC_VERSION, Photos.PERSON_ID,
                        Photos.DOWNLOAD_REQUIRED },
                "" + "_sync_account=? AND download_required != 0", new String[] { getAccount() }, null);
        try {// w ww .  j ava2 s .  c o  m
            if (cursor.getCount() != 0) {
                Bundle extras = new Bundle();
                extras.putString(ContentResolver.SYNC_EXTRAS_ACCOUNT, getAccount());
                extras.putBoolean(ContentResolver.SYNC_EXTRAS_FORCE, mSyncForced);
                extras.putString("feed", ContactsSyncAdapter.getPhotosFeedForAccount(getAccount()));
                getContext().getContentResolver().startSync(Contacts.CONTENT_URI, extras);
            }
        } finally {
            cursor.close();
        }
    }

    super.onSyncEnding(context, success);
}

From source file:com.android.providers.contacts.ContactsSyncAdapter.java

public static void updateSubscribedFeeds(ContentResolver cr, String account) {
    Set<String> feedsToSync = Sets.newHashSet();
    feedsToSync.add(getGroupsFeedForAccount(account));
    addContactsFeedsToSync(cr, account, feedsToSync);

    Cursor c = SubscribedFeeds.Feeds.query(cr, sSubscriptionProjection,
            SubscribedFeeds.Feeds.AUTHORITY + "=? AND " + SubscribedFeeds.Feeds._SYNC_ACCOUNT + "=?",
            new String[] { Contacts.AUTHORITY, account }, null);
    try {// www  . j  a v a2s  . co  m
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "scanning over subscriptions with authority " + Contacts.AUTHORITY + " and account "
                    + account);
        }
        c.moveToNext();
        while (!c.isAfterLast()) {
            String feedInCursor = c.getString(1);
            if (feedsToSync.contains(feedInCursor)) {
                feedsToSync.remove(feedInCursor);
                c.moveToNext();
            } else {
                c.deleteRow();
            }
        }
        c.commitUpdates();
    } finally {
        c.close();
    }

    // any feeds remaining in feedsToSync need a subscription
    for (String feed : feedsToSync) {
        SubscribedFeeds.addFeed(cr, feed, account, Contacts.AUTHORITY, ContactsClient.SERVICE);

        // request a sync of this feed
        Bundle extras = new Bundle();
        extras.putString(ContentResolver.SYNC_EXTRAS_ACCOUNT, account);
        extras.putString("feed", feed);
        cr.startSync(Contacts.CONTENT_URI, extras);
    }
}