I'm using code like this to get gmail email using content provider. My problem is that the "fromAddress" field contains sender's name instead of sender's email. For example it will contain "John Doe" but I would like to have "[email protected]".
The name in the field is the one set by the user in its email client, it does not come from my android contacts.
Here's the code I'm using:
ContentResolver resolver = context.getContentResolver();
cursor = resolver.query(Uri.parse("content://gmail-ls/conversations/[email protected]/", null, null, null, null);
cursor.moveToFirst();
String fromAddress = cursor.getString(cursor.getColumnIndexOrThrow("fromAddress")));
cursor.close();
I know the email is not in any fields coming from this URI. I've tried with this kind of URI: "content://gmail-ls/messages/[email protected]/39920384203052" but it always return a cursor with 0 records for a valid messageId.
Please help me get the sender's email for a given gmail email...
Thank you!
Start an Activity for Result
Intent intent = new new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);
OnActivityResult
Uri result = data.getData();
String con = result.getLastPathSegment();
cursor = getContentResolver().query(Phone.CONTENT_URI,
null, Phone.CONTACT_ID + "=?", new String[] { con },
null);
int id = cursor.getColumnIndex(Phone.DATA);
if(cursor.moveToFirst()){
String mail = cursor.getString(id);
Log.e("Email", mail);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With