gpt4 book ai didi

android - 在android中获取当前联系人

转载 作者:行者123 更新时间:2023-11-29 15:31:46 24 4
gpt4 key购买 nike

我知道有很多关于这个问题的问题。但我找不到任何帮助我的东西。我知道如何通过此代码获取所有具有电话号码的 android 联系人:

private List fillContactsList() {
List tmpList = new ArrayList();

Cursor c = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (c.moveToNext()) {
String ContactID = c.getString(c
.getColumnIndex(ContactsContract.Contacts._ID));
String name = c.getString(c
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String hasPhone = c
.getString(c
.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (Integer.parseInt(hasPhone) == 1) {
Cursor phoneCursor = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ "='" + ContactID + "'", null, null);
while (phoneCursor.moveToNext()) {
String number = phoneCursor
.getString(phoneCursor
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
con = new Contact();
con.setName(name);
con.setNumber(number);
tmpList.add(con);
}
phoneCursor.close();
}
}
c.close();
Collections.sort(tmpList);

return tmpList;
}

在我的设备上这样做的结果是 360 个联系人,但是当我通过手机打开我的联系人时,我只看到 120 个。那么我怎样才能只获得当前显示在手机联系人列表中的群组?

谢谢!萨尔

最佳答案

我不知道这是否是您的问题,但您可以尝试将 IN_VISIBLE_GROUP 添加到您的选择标准中。我不记得我头脑中的确切语法,但它应该是这样的:

Cursor c = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'", null, null);

关于android - 在android中获取当前联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5873207/

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