Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get email address

Tags:

android

gmail

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!

like image 944
Yan Avatar asked Jul 09 '11 03:07

Yan


1 Answers

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);
}
like image 100
Prasanna Avatar answered Sep 24 '22 06:09

Prasanna