0

这与具有两个文本视图的列表视图有关。第一个文本视图列出了联系人,而第二个文本视图假设显示来自相关联系人的收件箱中的消息数量。

我已经能够通过解析来计算设备上收件箱中的邮件数量

String inbox = "content://sms/inbox"

成一个字符串。但我想更深入,而不仅仅是一次性支付。是否可以更深入地进入收件箱并将邮件总数分离到相应的联系人?例如,如果我有 3 个联系人和 20 条消息,contact1 有 11 条消息,contact2 有 4 条消息,contact3 有 6 条消息。

4

1 回答 1

0

To get a count of how many texts in your inbox from each sender, you can use a SQL Group By clause. This is the popular trick to sneak a Group By clause into a ContentProvider:

Cursor cursor = getContentResolver().query(
        Uri.parse("content://sms/inbox/"),
        new String[] { "_id", "address", "count(*) as totals" },
        "1) Group By (address",
        null,
        null);

However this does not work for Android 4.0+. (For me designing ContentProviders without a Group By clause is like manufacturing a keyboard without numbers...) For 4.0+, I would suggest iterating through the regular cursor and sorting the messages yourself.

于 2012-05-14T21:26:57.350 回答