获取联系人Android 1.5的电话号码

时间:2011-03-16 01:08:04

标签: android sqlite contacts

对于给定的People._ID列表,如何获取联系人电话号码?

private void getCntctList(List<GroupMembers> mids){
    ArrayList<ContactItem> contact_list = new ArrayList<ContactItem>();
    ContentResolver cr = getContentResolver();
    String where = "People._ID IN (";
    for (GroupMembers g : mids) {
        where += g.personId + ",";
    }
    where = where.substring(0,where.length()-1) + ")";
    Cursor contactCur = cr.query(????, null, where, null, null);
    if (contactCur.getCount() > 0) {
        while (contactCur.moveToNext()) {

            ...

        }
    }
}

1 个答案:

答案 0 :(得分:1)

我假设你想要联系人的主要电话号码?你的代码错了。它应该是这样的:

String where = Phones.PERSON_ID + " IN (";
for (GroupMembers g : mids) {
   where += g.personId + ",";
}
where += ") AND " + Phones.ISPRIMARY + " <> 0";
Cursor c = cr.query(Phones.CONTENT_URI, null, where, null, null);
if (c != null && c.moveToFirst()) {
     do {
          // .....
     } while (c.moveToNext());
}