我想从 Android 中的联系人详细信息中获取电子邮件地址和电话号码。我可以拿起电话号码,但我希望当它选择电话号码时,它也将电子邮件地址添加到其相应的联系人 ID。所以我可以将它添加到数组列表中。谢谢
public void getContactslist()
{
ContentResolver contactResolver = getContentResolver();
Cursor cursor = contactResolver.query(Phone.CONTENT_URI , null,null,null, null);
// Cursor emails = contactResolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,null, null, null);
if(cursor.getCount() > 0)
{
cursor.moveToFirst();
do {
String number = cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
String displayname = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
long contactid = cursor.getLong(cursor.getColumnIndex(Phone.CONTACT_ID));
Cursor emails = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactid, null, null);
System.out.println("**emails*******"+number);
while (emails.moveToNext())
{
String email = emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
Log.e("Email", email);
}
}while (cursor.moveToNext() );
}
}