Insert SMS with multiple recipients into the Android system SMS provider

44 Views Asked by At

I develop an Android app that acts as the default messaging app and inserts messages into the system SMS provider. This has been generally working fine for both SMS and MMS messages for a while, but a user recently noticed that SMS messages with multiple recipients are not being handled correctly - the insertion succeeds, but the system messaging app shows the message with a only a single recipient, either the concatenation of the several recipients or just the first one.

My SMS insertion code looks something like this:

val smsMessage = ContentValues()
// Fill smsMessage with appropriate values
// 'recipientAddress' is the user-provided address of the recipient
val newThreadId = Telephony.Threads.getOrCreateThreadId(appContext, recipientAddress)
smsMessage.put("thread_id", newThreadId)
val insertUri = appContext.contentResolver.insert(Telephony.Sms.CONTENT_URI, smsMessage)

When an SMS message with multiple recipients is properly stored (e.g, by the standard system messaging app) in the system's SMS provider, a query to Telephony.Sms.CONTENT_URI will return the list of recipients stored in a single string for the Telephony.TextBasedSmsColumns.ADDRESS column, but I can't figure out how to properly do the insertion myself: with the code above, if Telephony.TextBasedSmsColumns.ADDRESS is set to the concatenation of the recipients into a string, then the insertion succeeds, but the recipients are not correctly set, as I described above.

I've tried using the multiple recipient form of getOrCreateThreadId and passing it the set of recipients, but the recipients are still not correctly set upon insertion.

I have not been able to find any documentation / examples of how to do this correctly. I suppose I could trawl the system messaging app source code, but it's really unfortunate that the Android documentation is often so lacking. Does anyone know how to do this, or have any other advice for me?

0

There are 0 best solutions below