2012-05-10 19 views
2

これは簡単な質問であれば、私はアンドロイドプログラミングの初心者です。アドレス帳から連絡先の総数を取得するにはどうすればよいですか?連絡先の総数 - android

+0

あなたは連絡先の総数またはすべての連絡先を何らかの詳細で表していますか? – Herry

+0

私は総数を意味しました。 – user1357350

+0

これを参照してください。 http://stackoverflow.com/questions/4290287/how-many-contacts-in-contact-list – Herry

答えて

9

(rawContactIdに接触ID値を渡す)特定RawContactIDのすべての電話番号の数を見つけるために、すべての連絡先

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

int count = cursor.getCount(); 

の電話番号の数を求めます。

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

int count = cursor.getCount(); 

ContactsListActivity構成に表示される連絡先の数は、次のクエリによって決定できます。人が複数のアカウントの下に入力されている場合ContactsContract.Contactsはそのようなすべての連絡先を組み合わせしかしのみ単一のインスタンスは、上記のクエリによって取得さ

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

int count = cursor.getCount(); 

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

+0

あなたの返事のための高尚!それを試してみる... :) – user1357350

+0

あなたはようこそ! – nnhthuan

+0

マニフェストには特別な権限が必要ですか? – moujib

0

で知ることができます。

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

int count = cursor.getCount();