拜托,我整天都在尝试通过电话获取所有联系人的电子邮件地址,但不知何故,我无法让它工作。请有人告诉我哪里出了问题。除了收到电子邮件之外,所有其他人都可以工作。提前致谢
Cursor cursor = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,null, null);
//now we have cusror with contacts and get diffrent value from cusror.
while (cursor.moveToNext()) {
String id = cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts._ID));
String name =cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
contactView.append("Name: ");
contactView.append(name);
contactView.append("\n");
if (Integer
.parseInt(cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
String phoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
contactView.append("Number: ");
contactView.append(phoneNumber);
contactView.append("\n");}
//get email cursor
Cursor ecursor = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = "+id,
null, null);
while (ecursor.moveToNext()) {
String email = ecursor.getString(ecursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
if(email != null){
contactView.append("email: ");
contactView.append(email);
contactView.append("\n");
}
}
ecursor.close();
}
cursor.close();