title: Get first name, last name, phone number from user profile?
body: <p>I'm trying to get user's info (first name, last name, phone, email, .etc) from profile. Below is my code, the weird thing is that there're several records (<code>cursor.moveToNext()</code> works several times), one of them contains email in the phone value, the other contains address in email field. All I need is one correct record, instead of picking and combining pieces.</p>
  
  <p>I do add required permissions, so there shouldn't be problems there.</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
      &lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt;
      &lt;uses-permission android:name="android.permission.READ_PROFILE" /&gt;
  </code></pre>
  
  <p>Any tip? thanks</p>
  
  <p>Below is my code </p>
  
  <pre><code>private static final String[] PERSONAL_ADDRESS_PROJ = {
              ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME,
              ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,
              ContactsContract.CommonDataKinds.Phone.NUMBER,
              ContactsContract.CommonDataKinds.Email.ADDRESS,
  
      };
  
      private static final int INDEX_GIVEN_NAME = 0;
      private static final int INDEX_FAMILY_NAME = INDEX_GIVEN_NAME + 1;
      private static final int INDEX_PHONE_NUMBER = INDEX_FAMILY_NAME + 1;
      private static final int INDEX_EMAIL = INDEX_PHONE_NUMBER + 1;
  
  private SignupModel searchForProfile() {
  
  
          final Uri uri = Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
                  ContactsContract.Contacts.Data.CONTENT_DIRECTORY);
  
          String selection = ContactsContract.Contacts.Data.MIMETYPE + " = ?" + " OR " +
                  ContactsContract.Contacts.Data.MIMETYPE + " = ?" + " OR " +
                  ContactsContract.Contacts.Data.MIMETYPE + " = ?" ;
  
          String [] args =  new String[]{ ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE,
                          ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,
                          ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE};
  
          Cursor cursor = mContext.getContentResolver().query(uri, PERSONAL_ADDRESS_PROJ, selection, args, null);
          SignupModel model;
  
          if (cursor != null &amp;&amp; cursor.moveToFirst()) {
              try {
                  do
                  {
                      final String givenName = cursor.getString(INDEX_GIVEN_NAME);
                      final String familyName = cursor.getString(INDEX_FAMILY_NAME);
                      final String phone = cursor.getString(INDEX_PHONE_NUMBER);
                      final String email = cursor.getString(INDEX_EMAIL);
  
                      model = new SignupModel(email,null,null,givenName, familyName, phone,null);
  
                  }while (cursor.moveToNext()); //loop for debugging purpose
  
              } catch (Exception e) {
                  model = null;
              } finally {
                  cursor.close();
              }
  
          } else {
              LogUtils.LOGD(TAG, "Couldn't find profile entry");
              model = null;
          }
          return model;
      }
  </code></pre>