0

so I am working on a SMS application project and I don't know how to only show the latest text per user, also how to count the conversation per sender.

This is my code:

private void refreshSMSInbox() {
    ContentResolver contentResolver = getContentResolver();
    Cursor smsInboxCursor = contentResolver.query(Uri.parse("content://sms/inbox"),null,null,null,null);
    int indexBody = smsInboxCursor.getColumnIndex("body");
    int indexAddress = smsInboxCursor.getColumnIndex("address");
    while (smsInboxCursor.moveToNext()) {
        PreviewMessage previewMessage = new PreviewMessage(smsInboxCursor.getString(indexAddress),smsInboxCursor.getString(indexBody),  1);
        mPreviewMessages.add(previewMessage);
    }
    mMessagesAdapter = new MessagesAdapter(mPreviewMessages,mContext);
    rvMessages.setAdapter(mMessagesAdapter);
}

This outputs every messages that the user has. If you know any documentation about android sms please kindly link it too, many thanks

Code-Me
  • 1
  • 2
  • AFAIK, this isn't really documented anywhere in the official docs, but the answer on the post now linked at the top of your question shows how to get both the most recent message and the message count for any/all conversations in one query. – Mike M. Aug 09 '17 at 04:26
  • in your query `Cursor smsInboxCursor = contentResolver.query(Uri.parse("content://sms/inbox"),null,null,null,null);` give it a date parameter for the `order by`. – Mehran Zamani Aug 09 '17 at 04:27

0 Answers0