gpt4 book ai didi

android - 使用 ContactsContract 光标按组获取联系人

转载 作者:搜寻专家 更新时间:2023-11-01 07:40:32 25 4
gpt4 key购买 nike

如何按 groupName 过滤返回的联系人?

@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
String groupName = parent.getItemAtPosition(pos).toString();
Log.i(this.toString(), String.format("Show Group: %s", groupName));

Cursor cur = this.getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String name = cur
.getString(cur
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (name != null) {
Log.i(this.toString(), String.format("Show: %s", name));
}
}

cur.close();
}
}

最佳答案

我能够使用以下查询按组过滤联系人:

Cursor c = this.managedQuery(Data.CONTENT_URI, new String[] {
Contacts.DISPLAY_NAME, Contacts._ID },
GroupMembership.GROUP_ROW_ID + " = ?",
new String[] { groupId }, Phone.TIMES_CONTACTED + " DESC");

显然您需要知道组 ID 才能完成此操作,我是如何使用 SimpleCursorAdapter 到带有以下 Cursor 的 Spinner:

Cursor c = managedQuery(Groups.CONTENT_URI,
new String[] { Groups.SYSTEM_ID, Groups._ID,},
Groups.SYSTEM_ID + " NOT NULL",
null, null);

关于android - 使用 ContactsContract 光标按组获取联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4372914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com