我有id联系,我怎么能得到他的小组(朋友,家人,最爱......)?
我试试:
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();
但我在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)
答案 0 :(得分:0)
试试这个,它适用于我:
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);
这要求您已经拥有组ID,并且可以通过查询ContactsContract.Groups