【发布时间】:2017-11-14 19:57:50
【问题描述】:
您好,我正在尝试从我的 Gmail 帐户中查找未读邮件的数量,为此我在 Google 中搜索了很多,但我没有得到 任何可行的解决方案,最后我从下面的链接中找到了一个文档,我遵循了相同的过程,但它总是返回未读邮件计数为 0,但在 Gmail 帐户中有 2 条未读邮件
http://android-developers.blogspot.in/2012/04/gmail-public-labels-api.html
有人可以帮帮我吗,我正在等待 3 天以来的正确解决方案
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;
}
【问题讨论】:
-
检查这个问题的答案。我认为“threadsUnread”是你需要的。stackoverflow.com/questions/44499338/…
-
您提供的链接没有解决方案-->stackoverflow.com/questions/44499338/…
-
如果需要,我会将我的示例代码分享给您,请建议我
-
你能把你的代码改成这个试试
cursor.getInt(GmailContract.Labels.NUM_UNREAD_CONVERSATIONS) -
你试过this吗?