我有以下代码来获取联系人的详细信息。"data":选择联系人后返回的Uri。
我需要确保我会在将来找到正确的联系人,所以我应该保存哪些内容以备将来使用?是"lookupUri“还是"lookupKey"?
Cursor c = activity.managedQuery(data, null, null, null, null);
c.moveToFirst();
String lookupKey = c.getString(c.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY ));
c.close();
// Next use that key to access the details of the contact in order to get the name and the photo
// Also, save it for future use.
// It will be used when we fetch the details from the database since the photo itself is not saved.
Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI,lookupKey);
Uri uri = ContactsContract.Contacts.lookupContact(activity.getContentResolver(), deviceDetails.lookupUri);发布于 2012-03-30 05:51:21
LookupKey是您想要存储的唯一标识符。
仅供参考;2.1中存在一个错误,当名称更改时,未同步的联系人LookupKey会发生更改。
发布于 2012-11-08 01:16:31
这是可行的。我的示例查找名称;在投影中添加或删除您想要的字段。
private String getContactNameFromAndroidKey (String key)
{
// Run query
Uri uri = Uri.parse (ContactsContract.Contacts.CONTENT_LOOKUP_URI + "/" + key);
String[] projection = new String[] {
Contacts._ID,
Contacts.DISPLAY_NAME,
};
Cursor cursor = context.getContentResolver().query (
uri,
projection,
null,
null,
null);
if (!cursor.moveToNext()) // move to first (and only) row.
throw new IllegalStateException ("contact no longer exists for key");
String name = cursor.getString(1);
cursor.close();
return name;
}https://stackoverflow.com/questions/9861905
复制相似问题