Reputation: 6654
Hi I am trying to get a contacts first name. I know how to get a contacts full name, but I cannot figure out how obtain just the name. any ideas?
Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String[] mPhoneNumberProjection = { PhoneLookup._ID, PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME };
Cursor cur = context.getContentResolver().query(lookupUri,mPhoneNumberProjection, null, null, null);
try {
if (cur.moveToFirst()) {
String name = cur.getString(2);
// do something with the name
}
} finally {
cur.close();
}
Upvotes: 2
Views: 1226
Reputation: 111555
I haven't personally tried this, but you may have to do a further RawContacts.CONTENT_URI
query against the PersonLookup.LOOKUP_KEY
from the first query, allowing you to retrieve the StructuredName.GIVEN_NAME field.
Upvotes: 4