title: How to retrieve Contact name and phone number in Android
body: <p>I'm trying to retrieve contact list with there name and phone numbers. I try following code:</p>
  
  <pre><code> // Get a cursor over every contact.
      Cursor cursor = getContentResolver().query(People.CONTENT_URI, 
                                                 null, null, null, null); 
      // Let the activity manage the cursor lifecycle.
      startManagingCursor(cursor);
      // Use the convenience properties to get the index of the columns
      int nameIdx = cursor.getColumnIndexOrThrow(People.NAME); 
  
      int phoneIdx = cursor. getColumnIndexOrThrow(People.NUMBER);
      String[] result = new String[cursor.getCount()];
      if (cursor.moveToFirst())
        do { 
          // Extract the name.
          String name = cursor.getString(nameIdx);
          // Extract the phone number.
          String phone = cursor.getString(phoneIdx);
          result[cursor.getPosition()] = name + "-" +" "+  phone;
        } while(cursor.moveToNext());
  </code></pre>
  
  <p>This code should return an array with the all contacts name and its phone number but this only returns name of the contact and returns NULL in phone number,</p>
  
  <p>Example Output:</p>
  
  <pre><code> John - null
  </code></pre>