How can I dump ALL of a contact's phone numbers?
<p>I can't figure this out... I'm using Android 2.1 SDK</p>

<p><strong>BUG:</strong>
*this will dump all the contacts' phone numbers <strong><em>except</em></strong> for CUSTOM LABEL phone numbers...*</p>

<p>How can I get it to dump phone numbers that have custom labels also?</p>

<p>So, for example 1 of my contacts has 3 phone numberss... 2 with custom label.. so for that contact only 1 phone number will be dumped to the log.</p>

<p>To <strong>run</strong>, just call <code>DumpContacts.readContacts(this);</code> from any Activity.</p>

<pre><code>package com.abc.debug;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.util.Log;

public class DumpContacts {
        private static final String TAG = "Dump Contacts";

        static public void readContacts(Context context)
        {
            String contactId, hasPhone, phoneNumber;
            ContentResolver cr=context.getContentResolver();
            Cursor phones, cc = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
            while (cc.moveToNext())
            {
                contactId = cc.getString(cc.getColumnIndex(ContactsContract.Contacts._ID));
                hasPhone = cc.getString(cc.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
                int nameFieldColumnIndex = cc.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME);
                String contactName = cc.getString(nameFieldColumnIndex);
                Log.v(TAG, "Contact id="+contactId+" name="+contactName);
                if (Integer.parseInt(hasPhone)==1)
                {
                    // You know it has a number so now query it like this
                    phones = cr.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                            null,
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null);
                    while (phones.moveToNext())
                    {
                        phoneNumber = phones.getString(phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER));
                        String label=getPhoneLabel(context, phones.getInt(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)),
                                phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL)));
                        Log.v(TAG, "  Phone"+phoneNumber+" with label="+label);
                    }
                    phones.close();
                }
            }
            cc.close();
        }

        static private String getPhoneLabel(Context context, int type, String label)
        {
            String s;
            switch(type)
            {
                case ContactsContract.CommonDataKinds.Phone.TYPE_HOME:
                    s = "home_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE:
                    s = "mobile_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_WORK:
                    s = "work_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK:
                    s = "fax_work_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME:
                    s = "fax_home_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_PAGER:
                    s = "pager_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_OTHER:
                    s = "other_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_CALLBACK:
                    s = "callback_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_CAR:
                    s = "car_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_COMPANY_MAIN:
                    s = "company_main_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_ISDN:
                    s = "isdn_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_MAIN:
                    s = "main_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_OTHER_FAX:
                    s = "other_fax_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_RADIO:
                    s = "radio_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_TELEX:
                    s = "telex_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_TTY_TDD:
                    s = "tty_tdd_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_WORK_MOBILE:
                    s = "work_mobile_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_WORK_PAGER:
                    s = "work_pager_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_ASSISTANT:
                    s = "assistant_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_MMS:
                    s = "mms_phone";
                    break;
                case ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM:
                    if(label == null)
                        s = "custom";
                    else
                        s = "custom:" + label;
                    break;
                default:
                    s = "default";
            }
            return s;
        }

}
</code></pre>

<p><a href="http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Phone.html" rel="nofollow">http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Phone.html</a></p>
