Android 2.0 如何获取联系人组中的显示名称和号码
我通过 id 获取给定组 id 中的联系人列表:
Cursor cur = ctx.managedQuery(ContactsContract.Data.CONTENT_URI,
new String[] { GroupMembership.GROUP_ROW_ID,
GroupMembership.CONTACT_ID },
GroupMembership.GROUP_ROW_ID + "=" + String.valueOf(id),
null, null);
if (cur.moveToFirst()) {
int groupIdx = cur.getColumnIndex(GroupMembership.GROUP_ROW_ID);
int personIdx = cur.getColumnIndex(GroupMembership.CONTACT_ID);
do {
if (cur.getLong(groupIdx) == id) {
Cursor ccur = ctx.getContentResolver().query( Phone.CONTENT_URI,
new String[] {Phone.NUMBER, Phone.TYPE,
Phone.DISPLAY_NAME },
Phone.CONTACT_ID +"="+ contactId,
null, null);
Log.e("Test: Number", ccur.getString(0))
Log.e("Test: Name", ccur.getString(2))
}
} while (cur.moveToNext());
}
但似乎无法正常工作。
I get a list of contacts in a given group id by id:
Cursor cur = ctx.managedQuery(ContactsContract.Data.CONTENT_URI,
new String[] { GroupMembership.GROUP_ROW_ID,
GroupMembership.CONTACT_ID },
GroupMembership.GROUP_ROW_ID + "=" + String.valueOf(id),
null, null);
if (cur.moveToFirst()) {
int groupIdx = cur.getColumnIndex(GroupMembership.GROUP_ROW_ID);
int personIdx = cur.getColumnIndex(GroupMembership.CONTACT_ID);
do {
if (cur.getLong(groupIdx) == id) {
Cursor ccur = ctx.getContentResolver().query( Phone.CONTENT_URI,
new String[] {Phone.NUMBER, Phone.TYPE,
Phone.DISPLAY_NAME },
Phone.CONTACT_ID +"="+ contactId,
null, null);
Log.e("Test: Number", ccur.getString(0))
Log.e("Test: Name", ccur.getString(2))
}
} while (cur.moveToNext());
}
But it seems that does not work correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能您缺少 mimetype。
Probably you are missing the mimetype.