我知道有很多关于这个问题的问题.但我找不到任何帮助我的东西.我知道如何通过此代码获取所有具有电话号码的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;
}Run Code Online (Sandbox Code Playgroud)
我的设备上的这个结果是360联系人,但是当我通过手机打开我的联系人时,我只看到120.所以如何才能获得当前在手机上的联系人列表中显示的群组?
谢谢!萨尔
我不知道这是不是你的问题,但你可以尝试添加IN_VISIBLE_GROUP你的选择标准.我不记得我头脑中的确切语法,但它是这样的:
Cursor c = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'", null, null);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
661 次 |
| 最近记录: |