请注意,有一种新方法可以做到这一点
我一直在尝试获取未读 Gmail 邮件的数量,但没有成功。
我读了Gmail.java and gmail4j从这个问题中取出的两个链接:Android - 如何找出用户有多少未读电子邮件?
但在阅读了所有这些内容以及其他几个讨论这个特定主题的网站之后,我的问题仍然存在:
Q: 如何获取 Gmail 未读邮件计数?
抱歉,如果它接缝有点坚持,但是我显然缺乏知识我自己从源头上找到了这一点。
PS:我想澄清一下,我想这样做而不必向用户询问凭据。
只需在问题中添加一些颜色即可让我向您展示我的应用程序的外观。
请注意,有一种新方法可以做到这一点
这是一些代码片段。不确定它是否有效,也无法测试它。但我希望它能帮助你继续调查。
public static final class LabelColumns {
public static final String CANONICAL_NAME = "canonicalName";
public static final String NAME = "name";
public static final String NUM_CONVERSATIONS = "numConversations";
public static final String NUM_UNREAD_CONVERSATIONS = "numUnreadConversations";
}
public void queryLabels(){
String account="[email protected]";
Uri LABELS_URI = Uri.parse("content://gmail-ls/labels/");
Uri ACCOUNT_URI = Uri.withAppendedPath(LABELS_URI, account);
ContentResolver contentResolver=myActivity.getContentResolver();
Cursor cursor = contentResolver.query(ACCOUNT_URI, null, null, null, null);
//iterate over all labels in the account
if (cursor.moveToFirst()) {
int unreadColumn = cursor.getColumnIndex(LabelColumns.NUM_UNREAD_CONVERSATIONS);
int nameColumn = cursor.getColumnIndex(LabelColumns.NAME);
do {
String name = cursor.getString(nameColumn);
String unread = cursor.getString(unreadColumn);//here's the value you need
} while (cursor.moveToNext());
}
}
需要许可
<uses-permission android:name="com.google.android.gm.permission.READ_GMAIL"/>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)