每个例子(网站,教程,电子书......),当我们需要查看一个联系人ID的电话号码时,我们需要重新查询如下代码:
Cursor contactCursor = getContentResolver().query(uri, null, null, null, null);
if (contactCursor.moveToFirst()){
id = contactCursor.getString(contactCursor.getColumnIndex(ContactsContract.Contacts._ID));
}
contactCursor.close();
//CHOOSE MOBILE PHONE OF CONTACT_ID
Cursor phoneCursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER},
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + id + " AND " + ContactsContract.CommonDataKinds.Phone.TYPE+ "=" +ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE ,
null, null);
但是,如果我直接在one contact uri
查询并过滤列_ID = contactID。我会在查询时遇到错误。这是我的代码:
String[] projector = new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER};
String selection = ContactsContract.CommonDataKinds.Phone.TYPE + "=" + ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE;
Cursor phoneContact = getContentResolver().query(uri, projector, selection, null, null);
注意:当有人从联系人列表中选择一个联系人时,上述代码中的uri对象会返回。
@Edit:这是我收到的错误: 这是我的错误:
java.lang.RuntimeException:传递结果失败 ResultInfo {who = null,request = 0,result = -1,data = Intent { DAT =含量://com.android.contacts/contacts/lookup/0r2-354F574135474F2741334D352743/2 flg = 0x1}}到activity {com.basic / com.data.SMSContactApp}: java.lang.IllegalArgumentException:列data1
无效
谢谢:)