How to get first name and last name from contact list?
Asked
Active
Viewed 934 times
1
-
1Keep trusting **Google** more!! – Paresh Mayani Apr 04 '12 at 05:45
-
Why dont you just search ones "Android How to get contact info programmatically?" – MKJParekh Apr 04 '12 at 06:07
2 Answers
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?