阅读所有联系人 Android 中的电话号码
我使用此代码来检索所有联系人姓名和电话号码:
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());
但是,这只会返回每个联系人的主要号码,但我也想获取辅助号码。我该怎么做?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
以下代码显示了读取所有电话号码和姓名的简单方法:
Following code shows an easy way to read all phone numbers and names:
您可以通过以下方式读取与联系人关联的所有电话号码:
请注意,此示例(与您的示例一样)使用已弃用的联系人 API。从 eclair 开始,它已被 ContactsContract API 取代。
You can read all of the telephone numbers associated with a contact in the following manner:
Please note that this example (like yours) uses the deprecated contacts API. From eclair onwards this has been replaced with the ContactsContract API.
此代码显示如何获取每个联系人的所有电话号码。
This code shows how to get all phone numbers for each contact.
如果有帮助的话,我有一个示例,它使用 ContactsContract API 首先按姓名查找联系人,然后迭代详细信息以查找特定的号码类型:
如何使用 ContactsContract 检索电话号码和电子邮件地址
In case it helps, I've got an example that uses the ContactsContract API to first find a contact by name, then it iterates through the details looking for specific number types:
How to use ContactsContract to retrieve phone numbers and email addresses
您可以使用以下方法获取所有手机联系人:
检查完整示例 这里......
You can get all phone contacts using this:
check complete example HERE...........
接受的答案有效,但没有给出唯一的数字。
查看此代码,它返回唯一的数字。
Accepted answer working but not given unique numbers.
See this code, it return unique numbers.
以同样的方式,使用其他“人员”参考来获取他们的其他号码
In the same way just get their other numbers using the other "People" references
这个一个终于给了我我正在寻找的答案。它可以让您检索手机上联系人的所有姓名和电话号码。
This one finally gave me the answer I was looking for. It lets you retrieve all the names and phone numbers of the contacts on the phone.
需求
我修复了我对清单权限的
注意:在清单上授予权限后,某些手机可能会拒绝,如果这样,您需要进入“设置”-->“应用领域-->找到您的应用程序,单击它并
打开所需的权限
I fixed my need belove
manifest permissions
Note: After giving permissions at manifest some mobile phones can deny if so you need to go Settings--> Applications--> find your application click on it and
turn On the permissions needed
您可以从这段代码中获取所有没有号码和没有姓名的联系人
可以做一件事,您必须在清单中授予联系人读取和写入的权限
之后,您可以为列表创建模型类,可用于添加所有联系人,这里是模型类
Enjoy :)
You can get all the contact all those which have no number and all those which have no name from this piece of code
One thing can be done you have to give the permission in the manifest for contact READ and WRITE
After that you can create the model class for the list which can be use to add all the contact here is the model class
Enjoy :)
使用 CursorLoader 在后台加载联系人:
Load contacts in background using CursorLoader:
以下介绍了如何使用
ContentsContract
API 获取电话簿中的联系人。您需要在
AndroidManifest.xml
中添加这些权限,然后,您可以运行此方法来循环访问所有联系人。
这是一个查询姓名和电话号码等字段的示例,您可以将自己配置为使用 CommonDataKinds,它查询联系人中的其他字段。
https://developer.android.com/reference/android/provider/ContactsContract。通用数据类型
Here's how to use
ContentsContract
API to fetch your contacts in your Phone Book.You'll need to add these permissions in your
AndroidManifest.xml
Then, you can run this method to loop through all your contacts.
Here's an example to query fields like Name and Phone Number, you can configure yourself to use CommonDataKinds, it query other fields in your Contact.
https://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds
获取联系人姓名(升序)和号码的代码
更多参考:在列表视图中显示联系人
Code to get contact name (Ascending order) and number
For more reference: show contact in listview