SMS Messages of a particular number not showing up on other devices Android

后端 未结 2 1854
臣服心动
臣服心动 2020-12-22 13:19

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

2条回答
  •  独厮守ぢ
    2020-12-22 13:52

    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);
    

提交回复
热议问题