How can I get an email address

I use this code to receive Gmail using a content provider. My problem is that the "fromAddress" field contains the name of the sender instead of the sender. For example, it will contain "John Doe", but I would like to have " john.doe@somewhere.net ".

The name in the field is the value set by the user in his mail client, it is not associated with my Android contacts.

Here is the code I'm using:

ContentResolver resolver = context.getContentResolver(); cursor = resolver.query(Uri.parse("content://gmail-ls/conversations/ myemail@gmail.com /", null, null, null, null); cursor.moveToFirst(); String fromAddress = cursor.getString(cursor.getColumnIndexOrThrow("fromAddress"))); cursor.close(); 

I know that the letter is not in any fields coming from this URI. I tried with this URI: "content: // gmail-ls / messages / myemail@gmail.com / 39920384203052", but it always returns a cursor with 0 entries for a valid messageId.

Please help me get the sender email for this Gmail email ...

Thanks!

+7
source share
2 answers

Run the action for the 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); } 
+2
source

I could not find the GMail content provider documentation for Android, but this may help you.

Open the HttpRequest object and submit it here. https://mail.google.com/mail/feed/atom . After authentication (standard HTTP authentication), you should receive the XML feed of your mailbox.

From there you can take it apart. The field you are looking for is input-> author-> email.

Hope this helps!

0
source

All Articles