Hello,

I'm adding a new contact using the 2.0 ContactsContract APIs and I was
just wondering if this is a safe way to get the "My Contacts" group to
set the group membership for my new contact. Or is there a better more
standard way to get it?

I'm using the literal string "System Group: My Contacts" when I query
the Groups table to get the source row for the My Contacts group.
I found this constant by poking around in the debugger, but It's not
documented anywhere that I could find, so I don't know if it's the
right thing to use.
Is there an actual constant somewhere that I should be using to find
the "My Contacts" group?

Code sample below: (I have the name of an account on the phone in the
local variable toAcct)
//------------
String where = ContactsContract.Groups.ACCOUNT_NAME + " =='" + toAcct
+ "' AND " + ContactsContract.Groups.TITLE + "=='System Group: My
Contacts'";
String groupSourceId = null;
String groupName = null;
try{
        Cursor cur = context.getContentResolver().query
(ContactsContract.Groups.CONTENT_URI, null, where, null, null);
        if(cur.moveToFirst()){
                int srcCol = cur.getColumnIndexOrThrow
(ContactsContract.Groups.SOURCE_ID);
                int nameCol = cur.getColumnIndexOrThrow
(ContactsContract.Groups.TITLE);
                groupSourceId = cur.getString(srcCol);
                groupName = cur.getString(nameCol);
        }
        cur.close();
        BmpLog.debug("Group Name is: " + groupName);
} catch (Exception e){
        e.printStackTrace();
}
//------------
Thanks for any insights.

Jake

-- 
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