您好,我正在尝试从我的Gmail帐户中查找未读邮件的数量,因为我在Google中搜索了很多,但我没有得到任何工作解决方案的 ,最后我发现了一个从下面的链接文件我也跟着相同的过程,但它始终返回未读邮件数为0,但在Gmail帐户有2个未读邮件如何从Gmail帐户中获取未读邮件数
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("[email protected]"),
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” 是你需要的.https://stackoverflow.com/questions/44499338/get-the-unread-mail-count-gmail-in-android –
有没有从你的链接提供的解决方案 - > https://stackoverflow.com/questions/44499338/get-the-unread-mail-count-gmail-in-android – Krish
如果我想分享我的示例代码给你,请建议我 – Krish