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();
}
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有亲自尝试过此操作,但您可能需要对第一个查询中的
PersonLookup.LOOKUP_KEY
执行进一步的RawContacts.CONTENT_URI
查询,以便检索 < href="http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.StructuredName.html" rel="nofollow noreferrer">StructuredName.GIVEN_NAME 字段。I haven't personally tried this, but you may have to do a further
RawContacts.CONTENT_URI
query against thePersonLookup.LOOKUP_KEY
from the first query, allowing you to retrieve the StructuredName.GIVEN_NAME field.