11

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.

4

2 に答える 2

13

thread_id手動で新しいものを作成する必要があります。通常contentResolver.insert(...)、複数の受信者メッセージには対応していません。新しいものを作成するにはthread_id、次の uri をクエリします

content://mms-sms/threadID

必要な受信者を追加して、最終的に次のようにします

content://mms-sms/threadID?recipient=9808&recipient=8808

したがって、完全な例は次のようになります。受信者98088808

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 が存在しない場合は新しい ID が作成されるか、既存の ID が返されます。

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あなたの SMS を挿入するために使用します。

注意すべき点がいくつかあります。

これthreadIdを使用して、 または の単一の受信者メッセージを挿入し9908たり8808、それぞれに新しい thread_id を作成したり、insertを指定せずに を実行したりしないでくださいthread_id

また、この部分には細心の注意を払ってくださいbuilder.appendQueryParameter(...)。キーがrecipientであり、 ではないことを確認してrecipientsください。使用recipientsしても機能しますが、常に同じものを取得しthread_id、すべての SMS が 1 つのスレッドで終了します。

于 2012-09-19T07:57:44.473 に答える
0

グループメッセージ用の新しいスレッドを作成し、それを新しいスレッドと個々のスレッドに挿入する必要があるようです。

于 2012-09-06T17:49:33.747 に答える