I am using the Telephony.Sms library to load in received and sent sms messages for the app I am working on. When I set the query selection to null (the third item in the que
Querying for SMS/MMS messages is very tricky, and varies a lot between different Android versions and between different makers.
This is the version that should work properly on all Android K+ devices:
HashSet phonesSet = new HashSet<>();
phonesSet.add(phoneNumber);
long threadId = Threads.getOrCreateThreadId(context, phonesSet); // get the thread-id of the specific conversation thread
Uri threadUri = ContentUris.withAppendedId(Threads.CONTENT_URI, threadId); // get the thread-uri
String[] projection = new String[]{MmsSms.TYPE_DISCRIMINATOR_COLUMN, BaseColumns._ID, Conversations.THREAD_ID,
Telephony.Sms.ADDRESS, Telephony.Sms.BODY, "sort_index", Telephony.Sms.DATE_SENT,
Telephony.Sms.READ, Telephony.Sms.TYPE, Telephony.Sms.STATUS, Telephony.Sms.LOCKED,
Telephony.Sms.ERROR_CODE, Telephony.Sms.SEEN};
Cursor cur = getContentResolver().query(threadUri, projection, null, null, null);
DatabaseUtils.dumpCursor(cur);