Getting phone number by type in Android
<p>I want to retrieve the phone numbers of selected contact based on type. I want to print the phone number type and associated phone number.</p>

<p>I could display the phone numbers of selected contact but not able to differentiate the type.</p>

<p>Below is the sample code I used:</p>

<pre><code>if (Integer.parseInt(cursor.getString(
  cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) &gt; 0) {
    Cursor phoneCursor = getContentResolver().query(
        ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
        null, 
        ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", 
        new String[]{contactId,}, null
    );
    while (phoneCursor.moveToNext()) {
        // Do something with phones
        System.out.println("phone numbers :"
         + phoneCursor.getString(
            phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)
         )
        );  
    }
    phoneCursor.close();
}
</code></pre>
