1

How to get first name and last name from contact list?

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
atrivedi
  • 348
  • 1
  • 4
  • 12

2 Answers2

1

Take a look at the Contact Manager sample project for code to do this.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
0

try this:

String whereName = ContactsContract.Data.MIMETYPE + " = ?";
String[] whereNameParams = new String[] { ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE };
Cursor nameCur = contentResolver.query(ContactsContract.Data.CONTENT_URI, null, whereName, whereNameParams, ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME);
while (nameCur.moveToNext()) {
    String given = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
   String[] str = given.split(' ');
       String fname=str[0];  // FIRST NAME
       String lname=str[str.length-1]; // LAST NAME
}
nameCur.close();

for more details see this post How to get the firstname and lastname from android contacts?

Community
  • 1
  • 1
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213