问题描述
我的工作在Android短信application.I可以通过以下code发送短信到单个联系人。
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);
现在我要发送短信到multicontacts.Some建议使用loop.SO我现在使用循环发送短信到多触点。
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);
每一个新的地址将创建一个新的线程ID。例如,如果我接收者的地址是x,那么线程ID 1,y的线程ID 2.And如果我想发送短信到X和Y,那么我该怎么写短信/发送表。如果我用的循环,那么就不会创建任何新的线程ID,因为发送地址X已经有了线程ID 1和y已经有线程ID 2.So消息将列在线程ID 1和2从不创建一个新的线程ID。
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.
我试图通过
values.put("thread_id", 33);
不过,再根据新的线程ID消息在默认的应用程序,但在我的应用程序没有列出。
But then the messages under new thread id do not listed in default app but in my app.
请帮我的朋友
编辑:我尝试使用0,然后读取生成的thread_id单,然后将下一个SMS与此的thread_id,仍然不工作。
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.
推荐答案
您需要创建一个新的的thread_id
手动,一个正常的 contentResolver.insert (...)
不会为多个收件人的邮件做。要创建新的的thread_id
您查询以下URI
You need to create a new thread_id
manually, a normal contentResolver.insert(...)
won't do for multiple recipient messages. To create the new thread_id
you query the following uri
内容:// MMS,SMS /线程标识
和将其追加必要的收件人,以便最终它看起来像这样
and to it append the necessary recipients so that finally it looks like this
内容:// MMS,SMS /主题ID收件人= 9808&放大器;收件人= 8808
所以,完整的例子是这样的。说出收件人 9808
和 8808
So the full example would look like this. Say the recipients are 9808
and 8808
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();
现在,您可以以正常的方式查询 URI
,这会给你一个的thread_id
,您可以使用指定的收件人,它会创建一个新的ID,如果不存在,或者返回现有之一。
Now you can query uri
in the normal way and this will give you a thread_id
that you can use for the recipients specified, it will create a new id if one doesn't exist or return an existing one.
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();
}
}
现在使用 threadId的
插入您的短信。
Now use threadId
to insert your SMSs.
有几件事情要注意。
不要使用此 threadId的
插入一个收件人消息或者 9908
或 8808
,为每个新的thread_id或只是做了一个插入
没有指定的thread_id
。
Do not use this threadId
to insert single recipient messages for either 9908
or 8808
, create a new thread_id for each or just do an insert
without specifying the thread_id
.
另外,要非常小心与 builder.appendQueryParameter(...)
部分,确保关键是收件人
,而不是收件人
,如果你使用收件人
它仍然会工作,但你总是会得到同样的的thread_id
和您的所有短信将结束在一个线程。
Also, be very careful with the builder.appendQueryParameter(...)
part, make sure the key is recipient
and not recipients
, if you use recipients
it will still work but you will always get the same thread_id
and all your SMSs will end up in one thread.
这篇关于写短信发送内容://短信/发送表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!