Android SDK-Get phone number of a specific contact
<p>How can I get the phone number of a specific contact by it's id?</p>

<p>So far I have this </p>

<pre><code>while (cursor.moveToNext()) {

        String displayName = cursor.getString(cursor
                .getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
        String contactId = cursor.getString(cursor.getColumnIndex( 
                 ContactsContract.Contacts._ID));



        if (Integer.parseInt(cursor.getString(
                   cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) &gt; 0) {


                Cursor phones = managedQuery( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, 
                ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{contactId}, null); 
                while (phones.moveToNext()) { 
                    phoneNumber = phones.getString( 
                    phones.getColumnIndex( 
                    ContactsContract.CommonDataKinds.Phone.NUMBER));                 
                    } 
                //phones.close(); 
         } 
         else
             phoneNumber = "No number";


            tv.append(displayName);
            tv.append(" ");
            tv.append(phoneNumber);
            tv.append("\n");
        }
        cursor.close();


    }
</code></pre>

<p>And while I get the correct display names, for each one of them I get the phone number of the first contact in the catalogue.
Any ideas?</p>
