How many contacts are in the contact list

How to find out how many contacts are in your contact list? I got a contact number, but one person can have several contacts, and I want to take this into account when looking for the total number of contacts in the contact list.

+5
source share
2 answers

To find the number of phone numbers of all contacts

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

int count = cursor.getCount();

To find the number of all phone numbers for a specific RawContactID (pass the value of the contact identifier to 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 component can be determined by the following query.

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

int count = cursor.getCount ();

, , , ContactsContract.Contacts .

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

int count = cursor.getCount();

ContactsContract.Contacts RawContacts http://developer.android.com/resources/articles/contacts.html

, !

+11

, , :

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

, managedQuery , bind:)

0

All Articles