2010-07-23 44 views
2

嗨我想获取联系人的名字。我知道如何获得联系人的全名,但我无法弄清楚如何获取姓名。有任何想法吗?android获取联系人的名字

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(); 
    } 

回答

4

我没有亲自尝试过,但你可能必须从第一个查询做对PersonLookup.LOOKUP_KEY进一步RawContacts.CONTENT_URI查询,让您检索StructuredName.GIVEN_NAME领域。