Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 486
Raymond Chenon Avatar asked Mar 22 '12 15:03

Raymond Chenon


1 Answers

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.

like image 189
gelupa Avatar answered Oct 08 '22 10:10

gelupa