阅读Android的所有联系人的电话号码 [英] Read all contact's phone numbers in android

查看:107
本文介绍了阅读Android的所有联系人的电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这个code检索所有联系人姓名和电话号码:

I'm using this code to retrieve all contact names and phone numbers:

String[] projection = new String[]
{
    People.NAME,
    People.NUMBER
};

Cursor c = ctx.getContentResolver().query(People.CONTENT_URI, projection, null, null, People.NAME + " ASC");
c.moveToFirst();

int nameCol = c.getColumnIndex(People.NAME);
int numCol = c.getColumnIndex(People.NUMBER);

int nContacts = c.getCount();

do
{
  // Do something
} while(c.moveToNext());

然而,这只会返回主号码为每个联系人,但我想要得到的辅助号码为好。我怎样才能做到这一点?

However, this will only return the primary number for each contact, but I want to get the secondary numbers as well. How can i do this?

推荐答案

可以读取所有与以下列方式的接触相关联的电话号码的

You can read all of the telephone numbers associated with a contact in the following manner:

Uri personUri = ContentUris.withAppendedId(People.CONTENT_URI, personId);
Uri phonesUri = Uri.withAppendedPath(personUri, People.Phones.CONTENT_DIRECTORY);
String[] proj = new String[] {Phones._ID, Phones.TYPE, Phones.NUMBER, Phones.LABEL}
Cursor cursor = contentResolver.query(phonesUri, proj, null, null, null);

请注意,这个例子(像你这样)采用德precated联系人API。从闪电起,这已被替换为<一个href="http://developer.android.com/intl/de/reference/android/provider/ContactsContract.html">ContactsContract API。

Please note that this example (like yours) uses the deprecated contacts API. From eclair onwards this has been replaced with the ContactsContract API.

这篇关于阅读Android的所有联系人的电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆