在Android中获取未读邮件计数gmail [英] Get the unread mail count gmail in Android
问题描述
我想获取有关设备帐户中未读电子邮件数量的信息.我已经看到有一种使用"Gmail标签公共API"的新方法
I want to get an int with the number of unread emails in the accounts of the device. I have seen that there is a new way to do this using the "Gmail Labels Public API"
http://android-developers.blogspot .in/2012/04/gmail-public-labels-api.html
我已经阅读了文档并下载了示例应用程序,它确实有效.但是我有两个问题:(
I have read the documentation and downloaded the sample application and it really works. But I have two problems: (
我的意图是对未读对话的数量有所了解,我尝试这样做:
My intention is to get an int with the number of unread conversations, i try this:
public static int getUnreadGmailCount(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;
}
但不起作用,总是返回"0",但是在gmail中,我有3条未读邮件
but not works, always returns "0",But in gmail i have 3 unread messages
真的很感谢您的帮助
感谢和问候
推荐答案
Please read carefully this document and also check this one
这篇关于在Android中获取未读邮件计数gmail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!