Raymond Chenon
Raymond Chenon

Reputation: 12702

query the latest SMS messages group by contact

Like the Message app, the first Activity displays the lastest SMS grouped by person and the count number.

Example I had exchanged 50 texts with Chris, 60 with Aline, 40 with Ray ... The app displays something like this

Chris (50) Hey how are you lately ?    
Aline (60) Let's catch up     
Ray   (40) Here is my number
Ethan (1)  I wrote a solution

I'm trying to do the same . I query all the SMS then I sort them. At least it's O(n) efficient .

Cursor cur = this.getContentResolver().query(Uri.parse("content://sms"), null, null, null, null);
int count = cur.getCount();

// iterate all the SMS
for (int i=1 ; i<=count ; i++){
    // processing
    ....

    cur.moveToNext();
}

Is there a way to query the latest messages (received or sent no draft type) grouped by person and get the number of SMS from a person ? I suppose there are multiple queries.

Upvotes: 6

Views: 2922

Answers (1)

gelupa
gelupa

Reputation: 712

I think this will do what you want:

Cursor cur = this.getContentResolver().query(Uri.parse( "content://mms-sms/conversations?simple=true"), null, null, null, "normalized_date desc" );

The returned cursor will contain the latest message in every conversation and the amount of messages in each conversation.

Upvotes: 9

Related Questions