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

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

问题描述

请注意这里是一种新的方法

解决方案

这是一些代码片段.不确定它是否有效,也无法对其进行测试.但我希望它能帮助你继续调查.

public static final class LabelColumns {public static final String CANONICAL_NAME = "canonicalName";public static final String NAME = "name";公共静态最终字符串 NUM_CONVERSATIONS = "numConversations";public static final String NUM_UNREAD_CONVERSATIONS = "numUnreadConversations";}公共无效查询标签(){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);//迭代帐户中的所有标签如果 (cursor.moveToFirst()) {int unreadColumn = cursor.getColumnIndex(LabelColumns.NUM_UNREAD_CONVERSATIONS);int nameColumn = cursor.getColumnIndex(LabelColumns.NAME);做 {String name = cursor.getString(nameColumn);String unread = cursor.getString(unreadColumn);//这里是你需要的值} while (cursor.moveToNext());}}

需要权限

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

Please note there is a new way of doing this

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

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:

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: I would like to clarify that I want to do it without having to ask the user for credentials.

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

Please note there is a new way of doing this

解决方案

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

Requires permission

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

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

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