2011-07-09 33 views
7

我使用这样的代码来使用内容提供商获取gmail电子邮件。我的问题是“fromAddress”字段包含发件人的名称而不是发件人的电子邮件。例如它将包含“John Doe”,但我希望拥有“[email protected]”。我如何获得电子邮件地址

该字段中的名称是用户在其电子邮件客户端中设置的名称,它不是来自我的android联系人。

下面是我使用的代码:我知道邮件是不是从这个URI来任何领域

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

。我尝试过使用这种URI:“content://gmail-ls/messages/[email protected]/39920384203052”,但它总是返回一个有效的messageId的0记录游标。

请帮我把发件人的电子邮件对于一个给定的Gmail电子邮件...

谢谢!

回答

0

我一直无法找到关于Android的GMail内容提供商的任何文档,但这可能会帮助你。

打开一个HttpRequest对象并将它发送到这里 - https://mail.google.com/mail/feed/atom一旦你进行了身份验证(标准HTTP身份验证),那么你应该得到你的收件箱的XML提要。

从那里你可以解析它。您正在寻找的领域是entry-> author-> email。

希望这会有所帮助!

2

开始一个活动为结果

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