联系人列表中有多少个联系人

发布于 2024-10-05 01:59:42 字数 74 浏览 4 评论 0原文

如何知道联系人列表中有多少个联系人?我获得了联系电话号码,但一个人可以有多个联系人,我想在查找联系人列表中的联系人总数时考虑到这一点。

How can I tell how many contacts there are in the contact list? I got the contact number, but one person can have more than one contact and I want to account for this in finding the total number of contacts in the contact list.

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

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

发布评论

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

评论(4

挽手叙旧 2024-10-12 01:59:42

查找所有联系人的电话号码计数

Cursor cursor =  managedQuery(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);

int count = cursor.getCount();

查找特定 RawContactID 的所有电话号码计数(在 rawContactId 中传递联系人 id 值)。

Cursor cursor =  managedQuery(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.RAW_CONTACT_ID + " = " + rawContactId, null, null);

    int count = cursor.getCount();

ContactsListActivity 中显示的联系人数量可以通过以下查询确定。

Cursor cursor =  managedQuery(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

int count = 游标.getCount();

但是,如果一个人已在多个帐户下输入,则上述查询只会获得一个实例,因为 ContactsContract.Contacts 组合了所有此类联系人。

Cursor cursor =  managedQuery(RawContacts.CONTENT_URI, null, null, null, null);

int count = 游标.getCount();

ContactsContract.Contacts 和 RawContacts 之间的关系可以在以下位置找到
http://developer.android.com/resources/articles/contacts.html

希望这能解决您的疑问!

To find the count of phone numbers of all the contacts

Cursor cursor =  managedQuery(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);

int count = cursor.getCount();

To find the count of all the phone numbers of a particular RawContactID (pass the contact id value in rawContactId).

Cursor cursor =  managedQuery(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.RAW_CONTACT_ID + " = " + rawContactId, null, null);

    int count = cursor.getCount();

The number of contacts displayed in the ContactsListActivity consists can be determined by following query.

Cursor cursor =  managedQuery(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

int count = cursor.getCount();

However if a person has been entered under multiple accounts then only a single instance is obtained by the above query as ContactsContract.Contacts combines all such contacts.

Cursor cursor =  managedQuery(RawContacts.CONTENT_URI, null, null, null, null);

int count = cursor.getCount();

The relation between ContactsContract.Contacts and RawContacts can be found out at
http://developer.android.com/resources/articles/contacts.html

Hope this resolves your doubt!

难以启齿的温柔 2024-10-12 01:59:42

一个非常古老的线程,但如果你想用电话号码来计算联系人,你可以使用这个:

Cursor cursor =  managedQuery(ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts.HAS_PHONE_NUMBER, null, null);
int count = cursor.getCount();

当然,现在不推荐使用 ManagedQuery,但这可以帮助绑定:)

A really old thread, but if you want to count contacts WITH phone numbers you can use this:

Cursor cursor =  managedQuery(ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts.HAS_PHONE_NUMBER, null, null);
int count = cursor.getCount();

Of course managedQuery is deprecated now, but this can help in a bind :)

淡水深流 2024-10-12 01:59:42

据我们所知, ManagedQuery 现已被弃用,我们可以像这样完成此任务

ContentResolver contentResolver = getContentResolver();
            Cursor cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
            int contactNewCount = cursor.getCount();
            cursor.close();

As we know managedQuery is now deprecated we can do this task like this

ContentResolver contentResolver = getContentResolver();
            Cursor cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
            int contactNewCount = cursor.getCount();
            cursor.close();
或十年 2024-10-12 01:59:42

如果有人仍然需要答案:

managementQuery 现已弃用,因此我们将使用 query 而不是 getContentResolver()

int contactCount = 0;

Cursor cursor = getContentResolver().query(android.provider.ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cursor != null) {
    contactCount = cursor.getCount();
    cursor.close();
}

注意:此答案已在 Android 10、11 和 12 上测试。

If anybody needs still the answer:

managedQuery is now deprecated, so we'll be using query instead from getContentResolver().

int contactCount = 0;

Cursor cursor = getContentResolver().query(android.provider.ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cursor != null) {
    contactCount = cursor.getCount();
    cursor.close();
}

Note: This answer is tested on Android 10, 11 and 12.

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