title: How to read emails programmatically in android?
body: <p>I am creating an app, in which I want to read all emails and want to display in a List View. I have been searching, but could not find any suitable way. I have tried below code:</p>
  
  <pre><code>private static final String[] PROJECTION = new String[] {
  ContactsContract.CommonDataKinds.Email.CONTACT_ID,
  ContactsContract.Contacts.DISPLAY_NAME,
  ContactsContract.CommonDataKinds.Email.DATA
  };
  
  ContentResolver cr = getContentResolver();
  Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,         PROJECTION, null, null, null);
  if (cursor != null) {
  try {
      final int contactIdIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.CONTACT_ID);
      final int displayNameIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
      final int emailIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA);
      long contactId;
      String displayName, address;
      while (cursor.moveToNext()) {
          contactId = cursor.getLong(contactIdIndex);
          displayName = cursor.getString(displayNameIndex);
          address = cursor.getString(emailIndex);
  
      }
  } finally {
      cursor.close();
      }
  }
  </code></pre>
  
  <p>but it return email address, what if I want to read actual emails? Is there any way? Does Android API expose this? One more thing, in one place I found below approach to get emails as</p>
  
  <pre><code>ContentResolver resolver = getContentResolver();
  Uri uriGmail = Uri.parse("content://gmail/");
  Cursor cursor = resolver.query(uriGmail, null, null, null, null);
  </code></pre>
  
  <p>But cursor returns null. What I believe there is no way to read emails from Android device. May be emails get saved in local storage(data base) of that app(let say Gmail app). I further explore Android documentation as mentioned below link but could not find the way.
  <a href="https://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Email.html" rel="nofollow noreferrer">https://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Email.html</a></p>
  
  <p>Thanks in advance.</p>