Taras
Taras

Reputation: 2576

Is it possible to import/export sms/mms on Blackberry10?

Is it possible to import/export sms/mms on Blackberry10 programmatically using cascades API??

Upvotes: 1

Views: 691

Answers (1)

Paul Bernhardt
Paul Bernhardt

Reputation: 491

SMS actually uses the same API as other messages (like email). The key difference is that you want to pick the SMS account specifically, and you probably want to build is as part of a conversation.

Using the Message part of the BlackBerry PIM API, try something like this:

            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;`

Upvotes: 2

Related Questions