Android : Iterating through SMS's by conversation sorted by date

Was a little fiddly to work out for newbies like myself, You can pass an argument to the .query() of the content resolver to tell it to sort by date, saves nasty custom SQLite interactions!, nice!

    public void refreshMessagelist() {
        
        mMessagesArrayAdapter.clear();
            String strUriInbox = "content://sms/conversations";
            Uri uriSmsConversations = Uri.parse(strUriInbox); 
            String strOrder = "date";
            Cursor cConversation = getContentResolver().query(uriSmsConversations, null, null, null, strOrder);
            
            while (cConversation.moveToNext()) 
            {
                try 
                {
                    String smsBody = cConversation.getString(cConversation.getColumnIndex("snippet"));
                    mMessagesArrayAdapter.add(smsBody);
                } 
                catch (Exception e) 
                {
                }
            }               
        }
0
Your rating: None