【发布时间】:2018-06-29 07:32:01
【问题描述】:
我正在尝试使用以下代码获取联系人姓名及其电话号码:
String id = readFile("contactlookupkey");
Uri uri = Uri.parse (ContactsContract.Contacts.CONTENT_LOOKUP_URI + "/" + id);
String[] projection = new String[] {
Contacts._ID,
Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
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);
String phone=cursor.getString(2);
cursor.close();
但由于 ContactsContract.CommonDataKinds.Phone.NUMBER,我在执行查询时遇到了非法参数异常。
问题是我没有看到任何其他方法可以在仍然使用 URI+loopkey 的同时获取电话号码。
如何获取电话号码?
【问题讨论】: