I am working on an android sms application.I can send sms to single contact by using the following code.
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
Now I want to send sms to multicontacts.Some suggest to use loop.SO now I am using loops to send sms to multicontact.
After sending each sms I write those values to sent table.
ContentValues values = new ContentValues();
values.put("address", mobNo);
values.put("body", msg);
getContentResolver().insert(Uri.parse("content://sms/sent"), values);
Every new address will create a new thread id.
For example if my receiver’s address is x, then thread id 1, for y thread id 2.And if I want to send sms to both x and y ,then how can I write in to sms/sent table.
If I use Loop,then it won’t create any new thread id, because send address x already have thread id 1 and y already have thread id 2.So messages will listed under thread id 1 and 2 never creates a new thread id.
I tried to manualy insert thread id by
values.put("thread_id", 33);
But then the messages under new thread id do not listed in default app but in my app.
Please help me friends
Edit:I tried using 0, and then reading the thread_id that was generated, then place the next sms with this thread_id, still doesn’t works.
You need to create a new
thread_idmanually, a normalcontentResolver.insert(...)won’t do for multiple recipient messages. To create the newthread_idyou query the following uricontent://mms-sms/threadIDand to it append the necessary recipients so that finally it looks like this
content://mms-sms/threadID?recipient=9808&recipient=8808So the full example would look like this. Say the recipients are
9808and8808Now you can query
uriin the normal way and this will give you athread_idthat you can use for the recipients specified, it will create a new id if one doesn’t exist or return an existing one.Now use
threadIdto insert your SMSs.A few things to note.
Do not use this
threadIdto insert single recipient messages for either9908or8808, create a new thread_id for each or just do aninsertwithout specifying thethread_id.Also, be very careful with the
builder.appendQueryParameter(...)part, make sure the key isrecipientand notrecipients, if you userecipientsit will still work but you will always get the samethread_idand all your SMSs will end up in one thread.