I’m using the following code to build a list of email addresses on the device to display on a ListActivity. Currently I can retrieve the email addresses ok, but they’re coming up in the form: null (email@address.com) instead of name (email@address.com) which is not ideal. The code I’m using should be retrieving the names as well:
Cursor c = getContentResolver().query(Email.CONTENT_URI,
new String[]{Email.CONTACT_ID, Email.DISPLAY_NAME, Email.DATA},
null, null, null);
addresses = new String[c.getCount()];
try{
c.moveToFirst();
for(int i = 0;i<c.getCount();i++){
addresses[i] = c.getString(1) + " (" + c.getString(2) + ")";
c.moveToNext();
}
} finally {
c.close();
}
Does anyone know what I’m doing wrong?
I’ve used this (definitely works on Android 2.2 on the Incredible; no promises on 2.3).