如何使用 Gmail.java 读取对话

发布于 2024-11-09 12:31:28 字数 2447 浏览 0 评论 0原文

我需要阅读 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戏舞 2024-11-16 12:31:28

自动应答:D

public void getMails(Context mContext){
    String account="[email protected]";
    ContentResolver contentResolver= mContext.getContentResolver();
    Cursor cursor = contentResolver.query(ACCOUNT_URI, null, null, null, null);



    Uri uri = Uri.parse(
            Gmail.AUTHORITY_PLUS_CONVERSATIONS + account + "/");
    Cursor cursorConversacion = contentResolver.query(
            uri, Gmail.CONVERSATION_PROJECTION, null, null, null);

    int j = 1;
    //check cursor
    if (cursorConversacion.moveToFirst()){

        Gmail gmail = new Gmail(mContext.getContentResolver());
        ConversationCursor cc = new ConversationCursor(gmail,account,cursorConversacion);

        do{ //extract some data for the example
            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 mc = new Gmail(contentResolver).getMessageCursorForConversationId(account, cc.getConversationId());


            if (mc.getCursor().moveToFirst()){
                int k=1;
                do{
                    //MessageCursor mc = new MessageCursor(gmail, contentResolver, account, cursorMessages);
                    Log.d("DEBUG","Mensaje " + k + " " + mc.getBody());
                    Log.d("DEBUG",mc.getFromAddress());

                    k++;
                }while ( (k < 10) && (mc.next()) ) ;

            }



            j++;
        }while ( (j< 20) && (cursorConversacion.moveToNext()) );

    }

此代码使用 Gmail.java(我的问题帖子中的链接),它是提取电子邮件正文的示例。您可以提取其他属性,例如 mailFrom 或发送日期

Autoanswer :D

public void getMails(Context mContext){
    String account="[email protected]";
    ContentResolver contentResolver= mContext.getContentResolver();
    Cursor cursor = contentResolver.query(ACCOUNT_URI, null, null, null, null);



    Uri uri = Uri.parse(
            Gmail.AUTHORITY_PLUS_CONVERSATIONS + account + "/");
    Cursor cursorConversacion = contentResolver.query(
            uri, Gmail.CONVERSATION_PROJECTION, null, null, null);

    int j = 1;
    //check cursor
    if (cursorConversacion.moveToFirst()){

        Gmail gmail = new Gmail(mContext.getContentResolver());
        ConversationCursor cc = new ConversationCursor(gmail,account,cursorConversacion);

        do{ //extract some data for the example
            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 mc = new Gmail(contentResolver).getMessageCursorForConversationId(account, cc.getConversationId());


            if (mc.getCursor().moveToFirst()){
                int k=1;
                do{
                    //MessageCursor mc = new MessageCursor(gmail, contentResolver, account, cursorMessages);
                    Log.d("DEBUG","Mensaje " + k + " " + mc.getBody());
                    Log.d("DEBUG",mc.getFromAddress());

                    k++;
                }while ( (k < 10) && (mc.next()) ) ;

            }



            j++;
        }while ( (j< 20) && (cursorConversacion.moveToNext()) );

    }

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文