Skip to content Skip to sidebar Skip to footer

How Do I Get The Count Of Sms Messages Per Contact Into A Textview?

I have a listview that displays the contacts on my device. What I'm trying to do is display the number of text messages my device has received from each contact into a textview wit

Solution 1:

Uri SMS_INBOX = Uri.parse("content://sms/conversations/");

Cursor c = getContentResolver().query(SMS_INBOX, null, null, null, null);

    startManagingCursor(c);
    String[] count = newString[c.getCount()];
    String[] snippet = newString[c.getCount()];
    String[] thread_id = newString[c.getCount()];

    c.moveToFirst();
    for (int i = 0; i < c.getCount(); i++) {
        count[i] = c.getString(c.getColumnIndexOrThrow("msg_count"))
                .toString();
        thread_id[i] = c.getString(c.getColumnIndexOrThrow("thread_id"))
                .toString();
        snippet[i] = c.getString(c.getColumnIndexOrThrow("snippet"))
                .toString();
        Log.v("count", count[i]);
        Log.v("thread", thread_id[i]);
        Log.v("snippet", snippet[i]);
        c.moveToNext();
    }

See log and problem solved. Dont repost the same question : How do I display the count of text messages received from a contact?

Solution 2:

I would perhaps add count(person) AS cnt to the columns String array and then I would add person as the groupBy argument to the query method.

EDIT:

And as pointed out by Jens, the GROUP BY paradigm isn't supported by the messaging ContentProvider.

What you could do is to create an in-memory database of your own at application startup (http://www.sqlite.org/inmemorydb.html) and copy-paste (query-insert) messages of interest from the system messaging database into your in-memory database. (NOTE! That this might fall out wrong if you are low on memory and have a tremendous amount of messages you're interested in). Since you'd be God in the in-memory database you could query it as you see fit with any exotic SQL querys you'd like...

Post a Comment for "How Do I Get The Count Of Sms Messages Per Contact Into A Textview?"