2

I have id contact, how i can get his group(friend, family, favorites...) ?

I try:

String where = String.format("%s = ?", ContactsContract.Groups._ID);
    String[] whereParams = new String[]{id};
    String[] selectColumns = {ContactsContract.Groups.TITLE};
    Cursor c = cr.query(Data.CONTENT_URI, selectColumns, where, whereParams, null); //THIS_LINE

    Log.d("Log", "cursor GROUP " + c.getString(0));
    c.close();

But i have exception in THIS_LINE:

E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-24188
Process: com.app.contactsmyclients, PID: 22499
java.lang.IllegalArgumentException: Invalid column title
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
        at android.content.ContentProviderProxy.query(ContentProviderNative.java:463)
        at android.content.ContentResolver.query(ContentResolver.java:476)
bvv
  • 1,893
  • 3
  • 14
  • 16

1 Answers1

0

try this, it works fine for me:

Uri groupURI = ContactsContract.Data.CONTENT_URI;
String[] projection = new String[]{
ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID ,
ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID};
Cursor c = managedQuery(groupURI,
projection,
ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID+"="+groupID,null,null);

this requires you to have the Group id already and that can be found by querying ContactsContract.Groups

Sagar Pilkhwal
  • 3,998
  • 2
  • 25
  • 77