检索组特定联系人的 [英] Retrieving group of particular contact
本文介绍了检索组特定联系人的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要检索的联络方式沿着与它所属的组。我得到了code列出所有的联系人组的电话。
I want to retrieve the contact details along with the group which it belongs to. I got the code to list all the contact groups in the phone.
Cursor groupC = getContentResolver().query(
ContactsContract.Groups.CONTENT_URI, null, null, null, null);
while (groupC.moveToNext()) {
String groupid =
groupC.getString(groupC.getColumnIndex(ContactsContract.Groups._ID));
Log.e("myTag", groupid);
String grouptitle =
groupC .getString(groupC.getColumnIndex(ContactsContract.Groups.TITLE));
Log.e("myTag", grouptitle);
}
groupC.close();
然后我试图查询特定联系人通过使用ID,但它总是显示有没有这样的列...
。
Cursor groupC = getContentResolver().query(
ContactsContract.Groups.CONTENT_URI,
null,
ContactsContract.Contacts._ID+"= ?",
new String[]{id},
null);
其中id是
Cursor cur = cr.query(
ContactsContract.Contacts.CONTENT_URI,
null,
null,
null,
null);
id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
如何使用特定的联系人ID来查询该组?
How to query the group using a particular contact id?
推荐答案
我找到了答案,我们应该通过原始接触ID和正确的MIME类型。
I found the answer.we should pass the raw contact-id and the correct mime type.
String where = ContactsContract.Data.RAW_CONTACT_ID
+ "="
+ Integer.parseInt(id)
+ " AND "
+ ContactsContract.Data.MIMETYPE
+ "='"
+ ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE
+ "'";
Cursor cursor = ctx
.getContentResolver()
.query(ContactsContract.Data.CONTENT_URI, null, where, null,
null);
startManagingCursor(cursor);
Log.e("Count is:", ""+ cursor.getCount());
while (cursor.moveToNext()) {
groupid = cursor
.getString(cursor.getColumnIndex(ContactsContract.Data.DATA1));
Log.e("groupid", groupid);
builder.append(groupid);
}String where = ContactsContract.Data.RAW_CONTACT_ID
+ "="
+ Integer.parseInt(id)
+ " AND "
+ ContactsContract.Data.MIMETYPE
+ "='"
+ ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE
+ "'";
Cursor cursor = ctx
.getContentResolver()
.query(ContactsContract.Data.CONTENT_URI, null, where, null,
null);
startManagingCursor(cursor);
Log.e("Count is:", ""+ cursor.getCount());
while (cursor.moveToNext()) {
groupid = cursor
.getString(cursor.getColumnIndex(ContactsContract.Data.DATA1));
Log.e("groupid", groupid);
break;
}
一个接触可以是在一个以上的基团,在这里它retrivr其第一组pnly
A contact may be in more than one group,here it retrivr its first group pnly.
我想这可能是有用的人......
I think this may be useful to somebody...
这篇关于检索组特定联系人的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文