How to obtain 'lookup key\" in Android Contacts API?

删除回忆录丶 提交于 2019-12-06 01:44:17
Amokrane Chentir

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 = getContentResolver().query(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));
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!