How to retrieve contact’s phone number (Android)?

I am having an absolute nightmare getting my contacts activity working – I understand this is a common problem, but I just can’t seem to apply existing solutions to my code – I just cannot get my head around this. Any help would be very much appreciated, I am tearing my hair out here.

public class nominateContactsActivity extends ListActivity {
public String strName;
public String strLoginCode;
public String strTelNo;

public void onCreate(Bundle savedInstanceState) {



    Cursor cursor = managedQuery(ContactsContract.Contacts.CONTENT_URI,
            null, null, null, null);
    String[] contacts = new String[] {ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER};       
    String[] columns = new String[] { ContactsContract.Contacts.DISPLAY_NAME};
    int[] to = new int[] { };

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
            android.R.layout.simple_list_item_multiple_choice, cursor, columns, to);

    Button finishButton = (Button) this.findViewById(;
    finishButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            SimpleCursorAdapter adapter = (SimpleCursorAdapter) nominateContactsActivity.this.getListAdapter();
            Cursor cursor = adapter.getCursor();

            ListView lv = nominateContactsActivity.this.getListView();
            SparseBooleanArray selectedItems = lv.getCheckedItemPositions();
            for (int i = 0; i < selectedItems.size(); i++) {

                int selectedPosition = selectedItems.keyAt(i);
                Log.d("", cursor.getString(cursor.getColumnIndex(
                        ContactsContract.Contacts.DISPLAY_NAME))+" is checked");
                Log.d("", "row id: "+adapter.getItemId(selectedPosition));

I am using the above code to return contacts list – this works fine, displays contact’s names in the listview as I wished. However, no phone numbers are retrieved, and I just cannot figure out how to get them.

Thank you


Below is the code to read all the contact numbers and name you can try out.

   Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
   while (phones.moveToNext())
      String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
      String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

Leave a Reply

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