Example usage for android.provider Contacts AUTHORITY

List of usage examples for android.provider Contacts AUTHORITY

Introduction

In this page you can find the example usage for android.provider Contacts AUTHORITY.

Prototype

String AUTHORITY

To view the source code for android.provider Contacts AUTHORITY.

Click Source Link

Usage

From source file:Main.java

/**
 * Transforms the given Uri and returns a Lookup-Uri that represents the contact.
 * For legacy contacts, a raw-contact lookup is performed. An {@link IllegalArgumentException}
 * can be thrown if the URI is null or the authority is not recognized.
 *
 * Do not call from the UI thread./*from  w w  w .j a v  a 2  s. c om*/
 */
@SuppressWarnings("deprecation")
public static Uri ensureIsContactUri(final ContentResolver resolver, final Uri uri)
        throws IllegalArgumentException {
    if (uri == null)
        throw new IllegalArgumentException("uri must not be null");

    final String authority = uri.getAuthority();

    // Current Style Uri?
    if (ContactsContract.AUTHORITY.equals(authority)) {
        final String type = resolver.getType(uri);
        // Contact-Uri? Good, return it
        if (ContactsContract.Contacts.CONTENT_ITEM_TYPE.equals(type)) {
            return uri;
        }

        // RawContact-Uri? Transform it to ContactUri
        if (RawContacts.CONTENT_ITEM_TYPE.equals(type)) {
            final long rawContactId = ContentUris.parseId(uri);
            return RawContacts.getContactLookupUri(resolver,
                    ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
        }

        // Anything else? We don't know what this is
        throw new IllegalArgumentException("uri format is unknown");
    }

    // Legacy Style? Convert to RawContact
    final String OBSOLETE_AUTHORITY = Contacts.AUTHORITY;
    if (OBSOLETE_AUTHORITY.equals(authority)) {
        // Legacy Format. Convert to RawContact-Uri and then lookup the contact
        final long rawContactId = ContentUris.parseId(uri);
        return RawContacts.getContactLookupUri(resolver,
                ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
    }

    throw new IllegalArgumentException("uri authority is unknown");
}

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 {//w  w  w  .ja  v  a2 s .  c  om
        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);
    }
}