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 开发者_如何学Goit will contain "John Doe" but I would like to have "john.doe@somewhere.net".
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/myemail@gmail.com/", 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/myemail@gmail.com/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);
}
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!
精彩评论