为什么小弟我或取不到ContendProvider里联系人的号码

为什么我或取不到ContendProvider里联系人的号码?代码是这样:ContentResolver cr getContentResolver()

为什么我或取不到ContendProvider里联系人的号码?
代码是这样:
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

int nameFieldColumnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);
int numberFieldColumnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER);

String hisName = cursor.getString(nameFieldColumnIndex);
String hisNumber = cursor.getString(numberFieldColumnIndex);

cursor.close();


问题就出在int numberFieldColumnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER);返回过来的始终是-1,但是获取联系人名字的代码返回都是正常的,求救~~~~sdk是2.2的

[解决办法]
我用老版本的代码可以:
Like this:
Cursor cur = activity.getContentResolver().query(People.CONTENT_URI,
null, null, null, null);
while (cur.moveToNext())
{
int columnIndex = cur.getColumnIndex(People.NAME);
String name = cur.getString(columnIndex);
columnIndex = cur.getColumnIndex(People._ID);
String id = cur.getString(columnIndex);
// 其它的都差不多
}
[解决办法]
android2.1取得通讯录联系人名字和电话号码

Java code
// 取得ContentResolver对象              ContentResolver cr = getContentResolver();                // 取得通讯录的光标              String orderBy = PhoneLookup.DISPLAY_NAME + " COLLATE LOCALIZED ASC";           Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, orderBy);                // 遍历通讯录           ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();           for(int i=0; i<cursor.getCount() ;i++)           {               HashMap<String, Object> map = new HashMap<String, Object>();                              cursor.moveToPosition(i);                              // No.               map.put(COLUMN_ID, i + 1);                              // 取得联系人名字                  int nameFieldColumnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);                  String name = cursor.getString(nameFieldColumnIndex);                map.put(COLUMN_NAME, name);                              // 取得联系人ID                  String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));                  Cursor phone = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,                       null,                       ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,                       null, null);                               String number = "";               // 取得电话号码(可能存在多个号码)                  for(int j = 0; j < phone.getCount(); j++)                 {                      phone.moveToPosition(j);                   String strPhoneNumber = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));                      if (j > 0) {                       number += " , ";                     }                   number += strPhoneNumber;                }                  map.put(COLUMN_NUMBER, number);               Log.d(TAG, "number = " + number);               phone.close();                               listItem.add(map);           }           cursor.close();                      // 生成适配器的Item和动态数组对应的元素           SimpleAdapter listItemAdapter = new SimpleAdapter(this,                   listItem,// 数据源                   R.layout.list_item,// ListItem的XML实现                   // 动态数组与ListItem对应的子项                   new String[] { COLUMN_ID, COLUMN_NAME, COLUMN_NUMBER },                      new int[] { R.id.TextView1, R.id.TextView2, R.id.TextView3 });           lv.setAdapter(listItemAdapter);         }
[解决办法]
最近一直被这个问题所困惑。


特别是想通过一个电话号码来查找联系人的姓名时,大家是通过什么方法来做的啊?

网上找的都是通过用户名,或遍历整个通信录,这在实际应用中,并不理想!

大家是怎么实际通过号码来查询姓名的啊??
[解决办法]
取电话号码要循环取,其实就是要查询两次,不知道是从哪个版本之后,就改成这个样子了。
你2.2的,肯定要循环取,代码参考2楼