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

发布于 2024-10-22 18:29:55 字数 605 浏览 0 评论 0原文

对于给定的 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()) {

            ...

        }
    }
}

For a given list of People._IDs how can I get the contacts phone number?

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()) {

            ...

        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可是我不能没有你 2024-10-29 18:29:55

我想您想知道联系人的主要电话号码?你的代码是错误的。它应该是这样的:

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());
}

I assume you want the primary phone number from the contact? Your code is wrong. It should be something like this:

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());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文