【发布时间】:2012-01-26 00:01:40
【问题描述】:
我希望使用PhoneLookup 甚至只是联系人查找键来获取特定Contact 的RAW_CONTACT_ID。
我知道联系人表有一个列 name_raw_contact_id 引用了 raw_contacts._id 列,但在使用联系人查找键查询 ContactsContract.Contacts.CONTENT_LOOKUP_URI 时似乎没有返回。
我的手机查询查询是:
String[] projection = new String[] {
PhoneLookup.DISPLAY_NAME, PhoneLookup.LOOKUP_KEY };
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
Cursor c = resolver.query(uri, projection, null, null, null);
然后我根据查找键查找Contact:
String[] contactProjection = new String[] {
ContactsContract.Contacts.NAME_RAW_CONTACT_ID
};
Uri contactUri = Uri.withAppendedPath(
ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
Cursor contactCursor = resolver.query(contactUri,
contactProjection, null, null, null);
但是,这不会编译,我得到了
cannot find symbol: variable NAME_RAW_CONTACT_ID
location: class android.provider.ContactsContract.Contacts
但android documentation 将NAME_RAW_CONTACT_ID 显示为一列。
有什么方法可以让我根据电话号码或查找键获得RAW_CONTACT_ID?
【问题讨论】:
-
在我见过的其他例子中,
number必须被编码。例如。Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));。为什么你的例子中没有? -
当时(在 ICS 之前),不需要它,而且谷歌文档在他们的示例中没有它(我记得)。我从来没有遇到过任何问题。也许他们已经在 ICS 中对其进行了更新,以获取编码电话。 Google 在这方面的文档现在也有
Uri.encode(phoneNumber),所以我会更新我的问题。