我正在尝试从手机的联系人中生成电子邮件列表,但我在专门获取电子邮件时遇到了麻烦。我可以得到姓名和电话号码,但不能得到电子邮件。ArrayList 大小在循环结束时均为 0。谁能发现我做错了什么,或者告诉我电子邮件与电话号码、姓名和其他信息有何不同?
ContentResolver cr = getContentResolver();
Cursor emailCur = cr.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
null, null);
ArrayList<String> emails = new ArrayList<String>();
ArrayList<String> emailTypes = new ArrayList<String>();
while (emailCur.moveToNext()) {
// This would allow you get several email addresses
// if the email addresses were stored in an array
String email = emailCur
.getString(emailCur
.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
String emailType = emailCur
.getString(emailCur
.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));
emails.add(email);
emailTypes.add(emailType);
}
emailCur.close();
Log.i("Emails Count", Integer.toString(emails.size()));
for (int i = 0; i < emails.size(); i++) {
Log.i("Emails " + i, emails.get(i));
}
Log.i("EmailTypes Count", Integer.toString(emailTypes.size()));
for (int i = 0; i < emailTypes.size(); i++) {
Log.i("EmailTypes " + i, emailTypes.get(i));
}