我正在使用以下代码从我的应用程序发送短信;
void App::sendSms(const QString &messageText, const QStringList &phoneNumbers) {
bb::pim::account::AccountService accountService;
bb::pim::message::MessageService messageService;
QList<Account> accountListy = accountService.accounts(bb::pim::account::Service::Messages,"sms-mms");
bb::pim::account::AccountKey smsAccountId = 0;
if(!accountListy.isEmpty()) {
smsAccountId = accountListy.first().id();
qDebug() << "SMS-MMS account ID:" << smsAccountId;
}
else {
qWarning() << "Could not find SMS account";
return;
}
QList<bb::pim::message::MessageContact> participants;
foreach(const QString &phoneNumber, phoneNumbers) {
bb::pim::message::MessageContact recipient = bb::pim::message::MessageContact(
-1, bb::pim::message::MessageContact::To,
phoneNumber, phoneNumber);
participants.append(recipient);
}
bb::pim::message::ConversationBuilder *conversationBuilder =
bb::pim::message::ConversationBuilder::create();
conversationBuilder->accountId(smsAccountId);
conversationBuilder->participants(participants);
bb::pim::message::Conversation conversation = *conversationBuilder;
bb::pim::message::ConversationKey conversationId = messageService.save(smsAccountId, conversation);
bb::pim::message::MessageBuilder *builder =
bb::pim::message::MessageBuilder::create(smsAccountId);
builder->conversationId(conversationId);
builder->addAttachment(bb::pim::message::Attachment("text/plain", "", messageText.toUtf8()));
foreach(const bb::pim::message::MessageContact recipient, participants) {
builder->addRecipient(recipient);
}
bb::pim::message::Message message = *builder;
messageService.send(smsAccountId, message);
delete builder;
delete conversationBuilder;
}
但是,每次它发送一条新的 SMS 时,它都会在 Text Messages UI 中创建一个新线程。我想知道是否有一种方法可以将新消息添加到已经存在的线程中,该线程将发送到它要发送到的号码?
谢谢!