0

I'm developing an Android app using "android.permission.SEND_SMS" to opne contact list and display it. My app run just fine, but when I pick a contact from my list it only display the first contact phone number for any contact I pick. This is my code. Thank you.

public void onActivityResult(int reqCode, int resultCode, Intent data) { 
    super.onActivityResult(reqCode, resultCode, data); 

     Cursor people = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                ContactsContract.CommonDataKinds.Phone.NUMBER}, 
                null, null, null);

      int indexNumber = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);

       people.moveToFirst();
       String number;
       do {
           number = people.getString(indexNumber);
       } while (people.moveToNext());
    phoneNumber.setText(number);
}
user1661865
  • 75
  • 1
  • 3
  • 5
  • you keep overwriting your String number variable so it kind of makes sense you only see one phone number. Instead of doing number = people... do something like number += " " + people... – ePeace Dec 20 '12 at 09:02
  • Thanks for your answer, I changed my code with your suggestion and I get all my contact list phone numbers. Im sure that this line is the problem: int indexNumber = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); but I have no idea how to fix it. – user1661865 Dec 20 '12 at 17:33

0 Answers0