0

我在 web android developer 官方中找到了这个功能

public final Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal)

现在,我想从 content://sms/sent 获取短信,使用 sms 的 thread_id 我只会得到最新的短信。

我将举例说明:

id   | thread_id |        phone     |       body

10       47
9        46 
8        47
7        45 
6        47 
5        43
4        45
3        42
2        41
1        47

我想收到的结果是:

 id   | thread_id |        phone     |       body

10       47
9        46     
7        45 
5        43
3        42
2        41

我该如何处理上面的查询?谢谢。

4

1 回答 1

0

您必须使用GROUP BY thread_id,在我的 github 存储库SmsMessenger中查看更多详细信息,您可以通过以下查询获取它:

    Cursor cursor = MyApplication.getContext().getContentResolver().query(Uri.parse("content://sms")
            , null
            , "address IS NOT NULL) GROUP BY (thread_id"
            , null
            , null);
   if (cursor != null && cursor.moveToFirst()) { // must check the result to prevent exception
        do {
   String messageText = cursor.getString(cursor.getColumnIndexOrThrow("body"));
   System.out.println("messageText : "+messageText );
} while (cursor.moveToNext());
于 2016-11-30T16:01:19.553 回答