我是 android 新手,每次我使用以下代码时,我都想在我的联系人列表中获取现有联系人的电子邮件,但我无法获得确切的联系人电子邮件,而是任何随机电子邮件。请帮助我更正此代码,我将不胜感激。
public void fetchingContacts(Context context) {
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
ContentResolver cr = context.getContentResolver();
Cursor crsr = cr.query(uri, null, null, null, null);
crsr.moveToFirst();
if (crsr.getCount() > 0) {
while (crsr.moveToNext()) {
ID = crsr
.getString(crsr
.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID));
id = crsr.getString(crsr.getColumnIndex(BaseColumns._ID));
NAME = crsr
.getString(crsr
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
NUMBER = crsr
.getString(crsr
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
arylist_contact_id.add(ID);
arylist_all_number.add(NUMBER);
arylist_all_names.add(NAME);
// ////////////
Cursor emailCur = cr.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
null, ContactsContract.CommonDataKinds.Email.CONTACT_ID
+ " = " + id, null, null);
while (emailCur.moveToNext()) {
email = emailCur
.getString(emailCur
.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
Log.v("fetchingEMAIL --- ", email);
}
emailCur.close();
Log.v("IN do while :: name and number ", ID + " , id :" + id
+ " " + NAME + " : " + NUMBER + " : " + email);
}
}
crsr.close();
}