Read Multiple Phone Numbers From Android Contacts List Programmatically

android-logo It is very easy to retrieve phone numbers in Android. This is how you can read multiple phone numbers from Android Contacts List programmatically. If a contact has multiple phone numbers, then You can retrieve all phone numbers and other details using Android’s inbuilt classes (Cursor and ContactsContract ) in Android. 



Below is the code snippet for reading all contact details from your Android device.

Step 1: Add below packages in your Activity class or from the class where you want to read all contacts.

Step 2:

Add below permission in your application’s Manifest file (AndroidManifest.xml).

Step 3:

Add the below function (Copy and paste) below code snippet into your in your Activity class or from the class where you want to read all contacts. You can read inline comments inside the code. I have added details code description inside the code snippet below.

Case 3: You just need to call above function from where you want to read phone numbers from the contacts list.

Code Description:

  • The parameter Context cntx’  in the function ReadPhoneContacts(Context cntx) is nothing but the this pointer  of your Acticity class or application Context.
  • There are 2 while loops in above code, First while loop is for the Cursor (cursor variable in the above code), which moves exactly once for each contact in the Android contacts list. Second while loop moves exactly once for each phone number associated with the contact name (contactName variable in the above code) using the second cursor (pCursor variable in the above code).
  • You can find the Contact Name in the variable(contactName variable in the above code). Then you will go into all phone numbers, which are associated with the Contact Name  (contactName variable in the above code).
  • In the Switch Case above (switch (phoneType) in the above code snippet), Each case having phone type like (TYPE_MOBILE, TYPE_HOME ect) in the switch case. In the switch case, you can find the variable phoneNo , which will provide the phone number for each phone type. Logs.e() function will print the numbers in DDMS if your phone/emulator is connected to your Eclipse editor. Else you can use the variable  phoneNo as per your requirement.

I hope this code snippet will help you at it’s best. If you have any concern or queries, then let me know. I will try to resolve your queries.

You might like to read about the complete tutorial for how to retrieve contacts and  then display in a ListView in Android.

Sample Code for retrieve Contacts List and display in a ListView in Android

Recommended Post for You – Add New Contact in Android Code Example.


Post By SmrutiRanjan (57 Posts)

Working @ Samsung as a Project Lead for Android Smartphones. I have been blogging since 2008. Previously I was writing articles for other bloggers, but finally I have started my own blog-"Techblogon".I am also an active contributor for the blog-"Gadgets n Gizmos World". Job is my necessity, but blogging is my passion.

Website: → Techblogon


Leave a Reply

Your email address will not be published. Required fields are marked *

+ 4 = twelve

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">