Hi i am trying to find Number of unread mails count from my Gmail account for this i searched lot in Google but i did not get any working solution and finally i found one document from below link i followed same process but it returns always Unread mails count as 0 but in Gmail account there is 2 Unread messages
http://android-developers.blogspot.in/2012/04/gmail-public-labels-api.html
Can some one help me please i am waiting for correct solution since 3 days
public static int getGmailCount(Context context) {
ContentResolver cr = context.getContentResolver();
Cursor cursor = cr.query(GmailContract.Labels.getLabelsUri("ensisinfo102@gmail.com"),
null,
null, null,
null);
if (cursor == null || cursor.isAfterLast()) {
Log.d(TAG, "No Gmail inbox information found for account.");
if (cursor != null) {
cursor.close();
}
return 0;
}
int count = 0;
while (cursor.moveToNext()) {
if (CANONICAL_NAME_INBOX_CATEGORY_PRIMARY.equals(cursor.getString(cursor.getColumnIndex(CANONICAL_NAME)))) {
count = cursor.getInt(cursor.getColumnIndex(NUM_UNREAD_CONVERSATIONS));
System.out.println("count is====>" + count);
break;
}
}
cursor.close();
return count;
}