如何知道联系人是否有电话? 下面是我的代码,它给了我所有的联系人姓名,但有些名字没有数字,所以我知道如何解决这种情况......
Cursor cursor = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext()) {
String contactId = cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts._ID));
contactName = cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
System.out.println("Id= " + contactId);
System.out.println("NAme= " + contactName);
nameArray.add(contactName);
Cursor phones = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = "
+ contactId, null, null);
while (phones.moveToNext()) {
phoneNumber = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
System.out.println("Phone no =" + phoneNumber);
contactsArray.add(phoneNumber);
}
phones.close();
}
cursor.close();