您好,我正在嘗試從我的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