Querying all phone numbers of a contact (SOLVED)
<p>i managed to write add program that upon the user click a button, he will be able to retrieve a phone number that will fill an editText box. The problem is that if a contact has multiple numbers, it will always take the top most number.</p>

<p>I have been reading another thread , <a href="http://stackoverflow.com/questions/6155612/getting-number-from-contacts-picker">Getting Number from Contacts Picker</a>, there is an answer, but i dont get it. As I am new to android programming,
I'll appreciate if anyone out there could give me step by step instructions</p>

<p><strong>Update</strong></p>

<p>After trying , i found that this works. The only problem is , how do i display the phone type together with the phone number</p>

<p>public class Test extends Activity {</p>

<pre><code>/** Called when the activity is first created. */
private static final int CONTACT_PICKER_RESULT=1001 ;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button browse = (Button) findViewById(R.id.do_email_picker);
    browse.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent contactPickerIntent= new Intent (Intent.ACTION_PICK,Contacts.CONTENT_URI);
            startActivityForResult(contactPickerIntent,CONTACT_PICKER_RESULT);
        }
    });

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode==RESULT_OK){
        switch(requestCode){
        case CONTACT_PICKER_RESULT:
                                    //handle contact results
                                    final EditText smsEntry = (EditText) findViewById(R.id.sms_to);
                                    Cursor cursor = null;
                                    String phoneNo = " ";
                                    List&lt;String&gt; allNumbers = new ArrayList&lt;String&gt;();

                                    int phoneIdx = 0;

                                    try{
                                        Uri result = data.getData();
                                        Log.v("Akiff", "Got a contact result: "+ result.toString());

                                        //get the contact id from the Uri
                                        String id = result.getLastPathSegment();

                                        //query for everything phone
                                        cursor= getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String []{id} , null);

                                         phoneIdx=cursor.getColumnIndex(Phone.DATA);

                                        //let's just get every phone number
                                        if(cursor.moveToFirst()){

                                              while(cursor.isAfterLast()==false){
                                                  phoneNo =cursor.getString(phoneIdx);

                                                  allNumbers.add(phoneNo);


                                                  cursor.moveToNext();
                                              }

                                        }else{
                                            Log.w("AKIFF", "No number");
                                            Toast.makeText(Test.this, "This contact has no number", Toast.LENGTH_LONG).show();
                                        }

                                    }catch(Exception e){
                                        Log.e("AKIFF", "error ",e);

                                    }finally{
                                        if(cursor!=null){
                                            cursor.close();
                                        }

                                        final String [] items = allNumbers.toArray(new String[allNumbers.size() ])  ;
                                        AlertDialog.Builder builder = new AlertDialog.Builder(Test.this);
                                        builder.setTitle("Choose a number: ");
                                        builder.setItems(items, new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int item) {
                                                // TODO Auto-generated method stub
                                                String selectedNumber = items[item].toString();
                                                selectedNumber = selectedNumber.replace("-","");
                                                //selectedNumber = selectedNumber.replace("+","");


                                                smsEntry.setText(selectedNumber);

                                            }
                                        });
                                        AlertDialog alert = builder.create();
                                        if(allNumbers.size()&gt;1){
                                            alert.show();

                                        }else{
                                            String selectedNumber= phoneNo.toString();
                                            selectedNumber=selectedNumber.replace("-", "");
                                            smsEntry.setText(selectedNumber);


                                        }
                                        if(phoneNo.length()==0){
                                            Log.d("Akiff", "No contact");


                                        }

                                    }
                                    break;

                            }
    }else{
        //gracefully handle failure
        Log.w("Akiff","Warning activity not okay");
    }
}
</code></pre>
