Cursor cursor=c.getContentResolver().query(Contacts.People.CONTENT_URI,null,null,null,null);
  while(cursor.moveToNext()){
  nameFieldColumnIndex = cursor.getColumnIndexOrThrow(Contacts.People.NAME);
    name = cursor.getString(nameFieldColumnIndex);
    numberFieldColumnIndex = cursor.getColumnIndexOrThrow(Contacts.People.NUMBER);
     number1 = cursor.getString(numberFieldColumnIndex);      
     //System.out.println(name);      
    // System.out.println(number1);
     if(number1==null){
      Toast.makeText(c, name+"请求跟踪", Toast.LENGTH_LONG).show(); 
      System.out.println("reach");
      
     }
     
     通讯录里放了两个人:shen 5556;dergin 1234   以上代码运行number1为null 名字打印出来为shen,dergin,[b]为什么没号码?    

解决方案 »

  1.   

    Cursor cursor=getContentResolver().query(Contacts.People.CONTENT_URI,null,null,null,null);
    if(cursor!=null){
    do{
    cursor.moveToFirst();
    String name=cursor.getString(cursor.getColumnIndex(People.NAME));
    String num=cursor.getString(cursor.getColumnIndex(Contacts.People.NUMBER));
    System.out.println(name);
    System.out.println(num);
    }while(cursor.moveToNext());
    }
    楼主试试吧!!
      

  2.   

    我也碰到这种情况,明明是两条数据,只显示一条,我的版本是2.3.3的,看了下API,contact这个接口改变了,People这个接口没有用了。contactcontract分了三张表来处理通信信息
      

  3.   

     Cursor c = getContentResolver().query(Phone.CONTENT_URI, null, null, null, null);
    String name=c.getString(c.getColumnIndex(Phone.DISPLAY_NAME));
    String number=c.getString(c.getColumnIndex(Phone.NUMBER));
    用上面这个,people已经过时了
    在新的Contacts API中,联系人数据被安排三个主要的表中:contacts, raw contacts and data。