如何获取“查找键"在Android的联系人API? [英] How to obtain 'lookup key" in Android Contacts API?

查看:122
本文介绍了如何获取“查找键"在Android的联系人API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是从Android文档


  

可以获取从接触本身的查找键,它是一个列
  在ContactsContract.Contacts表。


 乌里lookupUri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI,lookupKey)光标C = getContentResolver()查询(lookupUri,新的String [] {} Contacts.DISPLAY_NAME,...)。
尝试{
c.moveToFirst();
串的displayName = c.getString(0);
} {最后
c.close();
}

但无法得到它的工作。

我#2 走访答案这里和的这里但在静脉

任何帮助将是非常美联社preciated。


解决方案

文档中的code是有关如何使用的 lookupKey 的,一旦你得到它,而不是如何获得它

就像他们说的,你可以从联系人表中获取它。因此,为了得到的 lookupKey 的在您的联系人列表中的每个联系人,你可以使用下面的投影(前提是code的其余部分只能在这里显示的结果,你可以使用它是你想要的):

 的String [] =投影新的String [] {} ContactsContract.Contacts.LOOKUP_KEY;光标光标= this.managedQuery(ContactsContract.Contacts.CONTENT_URI,投影,NULL,NULL,NULL);
为(cursor.moveToFirst(); cursor.moveToNext(); cursor.isAfterLast()){
     Log.d(LOG_TAG,lookupKey接触:+ cursor.getString(1)+是:+ cursor.getString(0));
}

Following is from Android Documentation

You can acquire a lookup key from the contact itself, it is a column on the ContactsContract.Contacts table.

Uri lookupUri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey)

Cursor c = getContentResolver().query(lookupUri, new String[]{Contacts.DISPLAY_NAME},        ...);
try {
c.moveToFirst();
String displayName = c.getString(0);
} finally {
c.close();
}

but couldn't get it to work.

I visited answers on Stackoverflow here and here but in vein.

Any help will be highly appreciated.

解决方案

The code in the documentation is related to how to use the lookupKey once you get it, not how to obtain it.

Like they said, you can acquire it from the Contacts table. So, in order to get the lookupKey for each contact in your contacts list, you can use the following projection (the rest of the code provided is only here to show the results, you can use it as you want):

String [] PROJECTION = new String [] {  ContactsContract.Contacts.LOOKUP_KEY };

Cursor cursor = this.managedQuery(ContactsContract.Contacts.CONTENT_URI, PROJECTION, null, null, null);


for(cursor.moveToFirst(); cursor.moveToNext(); cursor.isAfterLast()) {
     Log.d(LOG_TAG, "lookupKey for contact:  " + cursor.getString(1) + ", is: " + cursor.getString(0));
}

这篇关于如何获取“查找键"在Android的联系人API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆