我正在检索所有联系人,但我只想检索那些具有多个手机号码的联系人。
这是我的代码段
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == 1) {
String[] numbers = null;
int i = 0;
String phoneNumber = null;
String id = null;
String name = null;
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(data.getData(), null, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{id}, null);
numbers = new String[pCur.getCount()];
while (pCur.moveToNext()) {
phoneNumber = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
numbers[i] = phoneNumber;
i++;
}
pCur.close();
etNumber.setText(phoneNumber);
}
}
}
cur.close();
AlertDialog.Builder ad = new AlertDialog.Builder(this);
ad.setTitle(name);
ad.setItems(numbers, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog adb = ad.create();
adb.show();
}
}