如何使用 Gmail.java 读取对话
我需要阅读 gmail 消息/对话来为盲人制作一个程序。 我正在使用 Gmail.java 访问 gmail 数据库。问题是我不知道如何访问邮件正文。
有人可以帮助我吗?
我的代码的一小段摘录:
Uri uri = Uri.parse( Gmail.AUTHORITY_PLUS_CONVERSATIONS + 帐户 + “/”); 光标cursorConversacion = contentResolver.query( uri,Gmail.CONVERSATION_PROJECTION,空,空,空);
int j = 1;
//Comprobamos que hay cursor
if (cursorConversacion.moveToFirst()){
Gmail gmail = new Gmail(mContext.getContentResolver());
ConversationCursor cc = new ConversationCursor(gmail,account,cursorConversacion);
do{
String cuenta = cc.getAccount();
String snippet = cc.getFromSnippetInstructions();
String subject = cc.getSubject();
String numMessages = "" + cc.getNumMessages();
String conversationID = "" + cc.getConversationId();
Log.d("DEBUG","\n\n\n MENSAJES " + j + " \n\n" +
" ID: " + conversationID +
" Num messages: " + numMessages +
" Subject: " + subject +
"\nCuenta: " + cuenta +
" snippet: " + snippet
);
//MessageCursor a partir de la conversacion
Uri uriMessages = Uri.parse(
Gmail.AUTHORITY_PLUS_CONVERSATIONS + account + "/" + conversationID + "/messages");
Cursor cursorMessages = contentResolver.query(
uri, Gmail.MESSAGE_PROJECTION, null, null, null);
if (cursorMessages.moveToFirst()){
int k=1;
do{
MessageCursor mc = new MessageCursor(gmail, contentResolver, account, cursorMessages);
Log.d("DEBUG","Mensaje " + k + " " + mc.getBody());
k++;
}while ( (k < 10) && (cursorMessages.moveToNext()) ) ;
}
j++;
}while ( (j< 20) && (cursorConversacion.moveToNext()) );
}
问题是我不知道如何访问邮件正文。
对对话的访问有效,但 messageCursor 无效。我知道/相信 messageCursor 的使用不是用于消息(对话的消息),并且我知道使用未注释的提供程序是一个坏主意(如果您有更好的提供程序)我,拜托!!!)但这是我发现解决我的问题的更好的解决方案。
寻求帮助,抱歉我的英语。
I need to read gmail messages/conversation to make a program for blind people.
I'm using Gmail.java to access gmail database. The problem its that i dont know how to access to the body of the mails.
Anyone can help me?
A small excerpt of my code:
Uri uri = Uri.parse(
Gmail.AUTHORITY_PLUS_CONVERSATIONS + account + "/");
Cursor cursorConversacion = contentResolver.query(
uri, Gmail.CONVERSATION_PROJECTION, null, null, null);
int j = 1;
//Comprobamos que hay cursor
if (cursorConversacion.moveToFirst()){
Gmail gmail = new Gmail(mContext.getContentResolver());
ConversationCursor cc = new ConversationCursor(gmail,account,cursorConversacion);
do{
String cuenta = cc.getAccount();
String snippet = cc.getFromSnippetInstructions();
String subject = cc.getSubject();
String numMessages = "" + cc.getNumMessages();
String conversationID = "" + cc.getConversationId();
Log.d("DEBUG","\n\n\n MENSAJES " + j + " \n\n" +
" ID: " + conversationID +
" Num messages: " + numMessages +
" Subject: " + subject +
"\nCuenta: " + cuenta +
" snippet: " + snippet
);
//MessageCursor a partir de la conversacion
Uri uriMessages = Uri.parse(
Gmail.AUTHORITY_PLUS_CONVERSATIONS + account + "/" + conversationID + "/messages");
Cursor cursorMessages = contentResolver.query(
uri, Gmail.MESSAGE_PROJECTION, null, null, null);
if (cursorMessages.moveToFirst()){
int k=1;
do{
MessageCursor mc = new MessageCursor(gmail, contentResolver, account, cursorMessages);
Log.d("DEBUG","Mensaje " + k + " " + mc.getBody());
k++;
}while ( (k < 10) && (cursorMessages.moveToNext()) ) ;
}
j++;
}while ( (j< 20) && (cursorConversacion.moveToNext()) );
}
The problem is that i don’t know how to access to the mail’s body.
The access to conversation works but the messageCursor doesn’t. I know/believe that the use of messageCursor isn't for message(a message of a conversation), and i know that the use of undecommented provider is a bad idea (if you have a better one tell me, please!!!!) but it is the better solution i found to solve my problem.
Ty for help, and sorry for my english.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自动应答:D
此代码使用 Gmail.java(我的问题帖子中的链接),它是提取电子邮件正文的示例。您可以提取其他属性,例如 mailFrom 或发送日期
Autoanswer :D
THIS CODE USES Gmail.java (link in my question post) and it's an example to extract the body of an emails. You can extract other attributes like mailFrom or date send