我正在使用以下代码从 android 检索联系人的名字和姓氏列表,但是我也想同时检索电子邮件:
Cursor1 = getContentResolver().query(
public List<String> getFullContactName()
{
List<String> name = new ArrayList<String>();
String[] projection = new String[] {Data.DATA2, Data.DATA3};
String where = Data.MIMETYPE + "='" + StructuredName.CONTENT_ITEM_TYPE + "'";
Uri uri = Data.CONTENT_URI;
ContentResolver contentResolver = getApplicationContext().getContentResolver();
Cursor cursor = contentResolver.query(uri,projection,where,null,null);
String firstName, lastName;
while (cursor.moveToNext())
{
firstName = cursor.getString(cursor.getColumnIndex(Data.DATA2));
lastName = cursor.getString(cursor.getColumnIndex(Data.DATA3));
name.add(firstName + " " + lastName);
Toast.makeText(getApplicationContext(), "First name"+firstName, Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "Second name"+lastName, Toast.LENGTH_LONG).show();
}
cursor.close();
cursor = null;
return name;
}
Cursor emails = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactId, null, null);
while (emails.moveToNext()) {
// This would allow you get several email addresses
String emailAddress = emails.getString(
emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
}
emails.close();
}
cursor.close();
我需要知道如何使用单个光标一起读取名字、姓氏电子邮件、电话号码,因为我需要在列表中获取详细信息,然后在列表视图中显示它们。我还没有参考资料,我可以使用单个光标获取详细信息。