Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to create a new <code>thread_id</code> manually, a normal <code>contentResolver.insert(...)</code> won't do for multiple recipient messages. To create the new <code>thread_id</code> you query the following uri</p> <p><code>content://mms-sms/threadID</code></p> <p>and to it append the necessary recipients so that finally it looks like this</p> <p><code>content://mms-sms/threadID?recipient=9808&amp;recipient=8808</code></p> <p>So the full example would look like this. Say the recipients are <code>9808</code> and <code>8808</code></p> <pre><code>Uri threadIdUri = Uri.parse('content://mms-sms/threadID'); Uri.Builder builder = threadIdUri.buildUpon(); String[] recipients = {"9808","8808"}; for(String recipient : recipients){ builder.appendQueryParameter("recipient", recipient); } Uri uri = builder.build(); </code></pre> <p>Now you can query <code>uri</code> in the normal way and this will give you a <code>thread_id</code> that you can use for the recipients specified, it will create a new id if one doesn't exist or return an existing one.</p> <pre><code>Long threadId = 0; Cursor cursor = getContentResolver().query(uri, new String[]{"_id"}, null, null, null); if (cursor != null) { try { if (cursor.moveToFirst()) { threadId = cursor.getLong(0); } } finally { cursor.close(); } } </code></pre> <p>Now use <code>threadId</code> to insert your SMSs.</p> <p>A few things to note. </p> <p>Do not use this <code>threadId</code> to insert single recipient messages for either <code>9908</code> or <code>8808</code>, create a new thread_id for each or just do an <code>insert</code> without specifying the <code>thread_id</code>.</p> <p>Also, be very careful with the <code>builder.appendQueryParameter(...)</code> part, make sure the key is <code>recipient</code> and not <code>recipients</code>, if you use <code>recipients</code> it will still work but you will always get the same <code>thread_id</code> and all your SMSs will end up in one thread.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload