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.
Autoanswer 😀
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