Hey there!

I'm querying the ContactsContract.Data table like the following:

[...]
       Uri contactsURI = ContactsContract.Data.CONTENT_URI;

          String[] projection = new String[] {
                    ContactsContract.Data._ID,
                    ContactsContract.Data.CONTACT_ID,
                    ContactsContract.Data.MIMETYPE,
                    ContactsContract.Data.DATA1,
                    ContactsContract.Data.DATA2,
                    ContactsContract.Data.DATA3,
                    ContactsContract.Data.DATA4,
                    ContactsContract.Data.DATA5,
                    ContactsContract.Data.DATA_VERSION
          };
          String where =      ContactsContract.Data.MIMETYPE + " = ?
OR " +
                              ContactsContract.Data.MIMETYPE + " = ?
OR " +
                              ContactsContract.Data.MIMETYPE + " = ?
OR " +
                              ContactsContract.Data.MIMETYPE + " = ?";

          String[] whereArgs = new String[] {
 
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE,
 
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,
 
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE,
 
ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE
          };

          Cursor contactsTable = managedQuery(contactsURI, projection,
where, whereArgs, null);
[...]


The problem is that the result is kind of unsorted. It would be best
if I could get the rows sorted by MIMETYPE (basically I need the
StructuredName to come on top) but grouped for each CONTACT_ID. This
means I'd like to get a person's name, then email/phone/im, etc. Then
the next person's name and their email/phone/im and so on..

So I thought this would best be achieved if I sorted like
Data.MIMETYPE + " DESC" and group by CONTACT_ID. However, there is no
possibility to use a group by parameter in a query() or managedQuery
(). The only database query I found that does take a group by
parameter is the SQLiteQueryBuilder.query(). However, I can't call
this one for the ContactsContract.Data Table since it doesn't take an
URI but an SQLiteDatabase.

How would you handle the sorting of the data? Should I perform a
single query for each CONTACT_ID? Wouldn't that be extremely cost
intensive?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to