是否可以使用级联API以编程方式在Blackberry10上导入/导出sms / mms?
答案 0 :(得分:2)
SMS实际上使用与其他消息(如电子邮件)相同的API。关键的区别在于您希望专门选择SMS帐户,并且您可能希望构建作为对话的一部分。
使用BlackBerry PIM API的Message部分,尝试以下方法:
MessageService messageService;
AccountService accountService;
//Get the SMS/MMS account
QList<Account> accountList = accountService.accounts(Service::Messages,"sms-mms");
AccountKey accountId = accountList.first().id();
// Create a contact to whom you want to send sms/mms. Put the right phone number in yourself
int contactKey = -1;
MessageContact recipient = MessageContact(contactKey, MessageContact::To,"5555555555", "5555555555");
//Create a conversation because sms/mms chats most of the time is a conversation
ConversationBuilder* conversationBuilder = ConversationBuilder::create();
conversationBuilder->accountId(accountId);
QList<MessageContact> participants;
participants.append(recipient);
conversationBuilder->participants(participants);
Conversation conversation = *conversationBuilder;
ConversationKey conversationId = messageService.save(accountId, conversation);
//Create a message Builder for sms/mms
MessageBuilder* messageBuilder = MessageBuilder::create(accountId);
messageBuilder->addRecipient(recipient);
// SMS API's handle body as an attachment.
QString body = "body of the sms";
messageBuilder->addAttachment(Attachment("text/plain","body.txt",body));
messageBuilder->conversationId(conversationId);
Message message;
message = *messageBuilder;
//Sending SMS/MMS
MessageKey key = messageService.send(accountId, message);
qDebug() << "+++++++ Message sent" << endl;`