首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LOOKUP_KEY和CONTENT_LOOKUP_URI

LOOKUP_KEY和CONTENT_LOOKUP_URI
EN

Stack Overflow用户
提问于 2012-03-26 00:35:03
回答 2查看 4K关注 0票数 0

我有以下代码来获取联系人的详细信息。"data":选择联系人后返回的Uri。

我需要确保我会在将来找到正确的联系人,所以我应该保存哪些内容以备将来使用?是"lookupUri“还是"lookupKey"?

代码语言:javascript
复制
    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);
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-30 05:51:21

LookupKey是您想要存储的唯一标识符。

仅供参考;2.1中存在一个错误,当名称更改时,未同步的联系人LookupKey会发生更改。

票数 2
EN

Stack Overflow用户

发布于 2012-11-08 01:16:31

这是可行的。我的示例查找名称;在投影中添加或删除您想要的字段。

代码语言:javascript
复制
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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9861905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档