Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the number of unread gmail mails (on android)

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.

alt text

Please note there is a new way of doing this

like image 533
Lord Otori Avatar asked Jun 07 '10 19:06

Lord Otori


People also ask

How can you tell how many unread emails you have in Gmail?

Click the dropdown on “Inbox Type” and choose the setting called “Unread First.” Step 3. You then need to choose how many unread emails you want to see at the top of your inbox. You can select 5, 10, 25, or 50.

How do I see the number of emails in my Gmail app?

Click on the “Advanced” tab. Scroll down to the “Unread message icon” option, click “Enable,” and then select “Save Changes.” Gmail will refresh, and from now on, the email icon in your Gmail tab will always have the number of unread messages displayed, no matter where you are in Gmail.

How do I filter unread emails in Gmail Mobile?

If you use the iOS or Android mobile app, here's how to sort unread emails in Gmail so that those messages appear at the top of your inbox: Open the Gmail app and tap Menu. Tap Settings and choose your Google account. Tap Inbox type and then tap Unread first.


1 Answers

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 protected]";
    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"/>
like image 66
Fedor Avatar answered Sep 22 '22 17:09

Fedor