Yan
Yan

Reputation: 71

How can I get email address

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!

Upvotes: 7

Views: 560

Answers (2)

Prasanna
Prasanna

Reputation: 236

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);
}

Upvotes: 2

mdinstuhl
mdinstuhl

Reputation: 150

I haven't been able to find any documentation on the GMail content provider for android but this might help you.

Open up a HttpRequest object and send it here - https://mail.google.com/mail/feed/atom Once you authenticate (standard HTTP auth) then you should get a XML feed of your inbox.

From there you can parse it. The field you are looking for is entry->author->email.

Hope this helps!

Upvotes: 0

Related Questions