如何获得的未读的Gmail邮件的数量(在Android) [英] How to get the number of unread gmail mails (on android)

查看:200
本文介绍了如何获得的未读的Gmail邮件的数量(在Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图让未读的Gmail邮件的数量,没有运气。

I've been trying to get the number of unread gmail mails with no luck.

我读过<一个href="http://www.google.com/$c$csearch/p?hl=en#uX1GffpyOZk/core/java/android/provider/Gmail.java&q=gmail.java&sa=N&cd=1&ct=rc"相对=nofollow> Gmail.java 和 gmail4j 两个链接取出到这个问题,这个网站:<一href="http://stackoverflow.com/questions/2779625/android-how-can-i-find-out-how-many-unread-email-the-user-has">Android - ?我如何才能知道有多少未读邮件的用户

I've read Gmail.java and gmail4j both links taken out of this site from this question: Android - How can I find out how many unread email the user has?

不过还是后看了这一切,一对夫妇的其他网站,谈到这个特定主题我的问题是:

But still after having read all of that and a couple of other sites that talked about this particular subject my question remains:

问::我怎样​​才能获得Gmail的未读​​邮件数

Q: How can I get the Gmail Unread Count?

很抱歉,如果它接缝有点坚持,但我清楚地缺乏知识。

Sorry if it seams a bit insistent but I clearly lack the knowledge to find this out on my own from the source.

PS:我想澄清的是,我想这样做,而不必要求用户提供凭据。

PS: I would like to clarify that I want to do it without having to ask the user for credentials.

仅有2添加一些颜色的问题让我告诉你我的应用程序的外观。

Just 2 add some colors to the question let me show you the looks of my app.

推荐答案

下面是一些code段。不知道它的工作原理,并不能对其进行测试。但我希望它会帮助你继续进行调查。

Here's some code snippet. Not sure it works and can't test it. But I hope it will help you to continue the investigation.

public static final class LabelColumns {
    public static final String CANONICAL_NAME = "canonicalName";
    public static final String NAME = "name";
    public static final String NUM_CONVERSATIONS = "numConversations";
    public static final String NUM_UNREAD_CONVERSATIONS = "numUnreadConversations";
}

public void queryLabels(){
    String account="email@company.com";
    Uri LABELS_URI = Uri.parse("content://gmail-ls/labels/");
    Uri ACCOUNT_URI = Uri.withAppendedPath(LABELS_URI, account);
    ContentResolver contentResolver=myActivity.getContentResolver();
    Cursor cursor = contentResolver.query(ACCOUNT_URI, null, null, null, null);

    //iterate over all labels in the account
    if (cursor.moveToFirst()) {
        int unreadColumn = cursor.getColumnIndex(LabelColumns.NUM_UNREAD_CONVERSATIONS);
        int nameColumn = cursor.getColumnIndex(LabelColumns.NAME);
        do {
            String name = cursor.getString(nameColumn);
            String unread = cursor.getString(unreadColumn);//here's the value you need
        } while (cursor.moveToNext());
    }
}

要求允许

<uses-permission android:name="com.google.android.gm.permission.READ_GMAIL"/>

这篇关于如何获得的未读的Gmail邮件的数量(在Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆