How to get only most recent SMS to use in conversation view?

后端 未结 1 2007
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-21 09:10

I am trying to create an sms conversation list. I am using this code to get a cursor:

Cursor cursor = activity.getContentResolver().query(Uri.parse(\"conten         


        
1条回答
  •  生来不讨喜
    2020-12-21 10:00

    Querying the "content://sms/conversations" URI (Telephony.Sms.Conversations.CONTENT_URI) will return a summary of each conversation, with the "snippet" column (Telephony.Sms.Conversations.SNIPPET) being the last message in each.

    This query will also return with a "msg_count" column (Telephony.Sms.Conversations.MESSAGE_COUNT) - which is pretty self-explanatory - and a "thread_id" column (Telephony.Sms.Conversations.THREAD_ID), which can be used to retrieve a complete conversation, by querying with that ID appended to the conversations URI. For example:

    String threadId = ...
    Uri convoUri = Telephony.Sms.Conversations.CONTENT_URI
                   .buildUpon().appendPath(threadId).build();
    

    Do note that these queries will return only SMS messages. If you want MMS as well, Telephony.Mms and Telephony.MmsSms have similar URIs.

    0 讨论(0)
提交回复
热议问题