title: Android: ContactsContract.Contacts.HAS_PHONE_NUMBER returns NULL
body: <p>I am trying to use provider <code>ContactsContract</code> for retrieving contacts information. Before fetching the <code>Phone Numbers</code> of contacts, I am checking whether contacts have phone numbers. For that I am using uri <code>ContactsContract.Contacts.HAS_PHONE_NUMBER</code> but on some devices it returns <code>1 or 0</code> and returns <code>NULL</code> on others. I am testing on <code>Android 2.3.1</code>, it returns <code>NULL</code> here. When tried to debug, <code>String phonenumber = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));</code>, It shows the mobile number. Can anyone please point out why the behaviour is different. I have checked the API of <code>ContactsContract</code>, its <code>level 5</code> which means <code>devices 2.3+</code> can use this. I am getting the following exception:</p>
  
  <h2>Exception</h2>
  
  <pre><code>06-03 13:01:51.065: E/AndroidRuntime(545): java.lang.RuntimeException: 
  Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { dat=content://com.android.contacts/data/2 flg=0x1 (has extras) }} 
  to activity {com.tzoomers.birthdaysdiary/com.tzoomers.birthdaysdiary.BirthdaysDiary}:
  java.lang.IllegalStateException: get field slot from row 0 col -1 failed
  </code></pre>
  
  <h2>Start Contacts Picker Activity</h2>
  
  <pre><code>private void addFromContacts()
      {
          Intent contactIntent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds
                  .Phone.CONTENT_URI);
          this.context.startActivityForResult(contactIntent, CONTACT_SELECTED);
      }
  </code></pre>
  
  <h2>onActivityResult</h2>
  
  <pre><code>@Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          // TODO Auto-generated method stub
          super.onActivityResult(requestCode, resultCode, data);
          switch(requestCode)
          {
          case CONTACT_SELECTED:
              if(resultCode == Activity.RESULT_OK)
              {
                  Uri contactData = data.getData();
                  Cursor c =  managedQuery(contactData, null, null, null, null);
                  if (c.moveToFirst()) {
                      int cId;
                      String phoneNumber = "";
                    String name = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                    cId = c.getInt(c.getColumnIndex(
                              ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
  
                    int hasPhone = Integer.parseInt(c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)));
  
                    if(hasPhone &gt; 0)
                    {
                      phoneNumber = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                    }
                  }
              }
              break;
          }
      }
  </code></pre>