How to read the last 3 cm from the inbox on Android?

I used this code

String msgData = ""; Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null); cursor.moveToFirst(); do{ for(int idx=0;idx<cursor.getColumnCount();idx++) { msgData += " " + cursor.getColumnName(idx) + ":" + cursor.getString(idx); } }while(cursor.moveToNext()); 

.. and it works, but it returns more data than I want.

How to read the last 3 sms (only msg and sender)?

+4
source share
1 answer

Just sort the results by date and use the limit clause:

 getContentResolver().query(SMS_INBOX, new String[] {body, address}, null, null, "date desc limit 3"); 
+9
source

Source: https://habr.com/ru/post/1446059/


All Articles