从一个联系人问题中检索所有号码

Retrieve all numbers from one contact issue

我知道这是一个常见问题,因为我找到了很多关于它的答案,但我仍然有一个关于 phone 号码检索的问题。

我想从 PICK_CONTACT activity 中选择的一个联系人获取所有号码。

这是我在 onActivityResult() 块中的代码

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

    switch (reqCode) {
        case (PICK_CONTACT) :
            if (resultCode == Activity.RESULT_OK) {

                ArrayList<String> allContacts = new ArrayList<String>();

                Uri contactData = data.getData();
                Cursor c =  getContentResolver().query(contactData, null, null, null, null);
                while (c.moveToNext()) {

                    String contact_id = c.getString(c.getColumnIndex( _ID ));
                    String hasPhone =c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));

                    if (hasPhone.equalsIgnoreCase("1")) {
                        Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { contact_id }, null);
                        while (phones.moveToNext())
                        {
                            String contactNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                            allContacts.add(contactNumber);

                            break;
                        }
                        phones.close();

                    }
                    String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                    TXT_EmergencyContactNameProfile.setText(name);
                }

            }
            break;
    }
}

我希望循环 while (phones.moveToNext()) 得到所有不同的数字...但没有

非常感谢您;)

尝试删除 while 循环中的 "break;"。