查找联系人Android时出错 [英] Error in looking up a contact Android
本文介绍了查找联系人Android时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我要访问特定联系人时出现错误.
I am getting an error when I want to access the a specific contact.
java.lang.IllegalArgumentException:无效的列contact_id
java.lang.IllegalArgumentException: Invalid column contact_id
这是示例代码:
String number = "0877777777";
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String[] projection = new String[]{ ContactsContract.PhoneLookup.CONTACT_ID };
Cursor cur = getActivity().getContentResolver().query(uri, projection, null, null, null);
// if other contacts have that phone as well, we simply take the first contact found.
if (cur != null && cur.moveToNext()) {
Long id = cur.getLong(0);
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(id));
intent.setData(contactUri);
startActivity(intent);
cur.close();
}
该错误在投影中,但是我不确定如何解决. 该号码将保存在被测手机上. 任何解决问题的建议将不胜感激.
The error is in the projection but I am not sure how to fix it. The number is saved on the phone under test. Any advice on solving the problem would be much appreciated.
推荐答案
只需将ContactsContract.PhoneLookup.CONTACT_ID
更改为ContactsContract.PhoneLookup._ID
.
PhoneLookup
中的_ID
仅表示CONTACT_ID
请参阅此处: https://developer.android.com/reference/android/provider/ContactsContract.PhoneLookup.html
这篇关于查找联系人Android时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文