Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
PJDavis1970
Posts: 44
Registered: ‎01-22-2013
My Device: Z10, Q10, Z10 Alpha
Accepted Solution

Invoke SMS

Hi,

 

I am looking for a way to invoke the standard SMS mechanism in QML.  I have searched and found many examples in here of sending and receiving SMS's but it is using its own code.  All I wish to do is pass the number and message into the phones actual SMS system..

 

Similar in the way I make a phone call with this QML code.

 

Also while on subject..  Is there a way to do same thing with Email.

 

                function makePhoneCall( arg1 ) {                 
                    phone.requestDialpad( arg1.NUMBER );  
                }

 Thanks

 

Contributor
PJDavis1970
Posts: 44
Registered: ‎01-22-2013
My Device: Z10, Q10, Z10 Alpha

Re: Invoke SMS

I found the solution to this so will share for those who also need answers.

 

OK first in my WebView I recieve a message from javascript with a single json string containing number and message.

 

{"NUMBER":"0123456789","TEXT":"this is a message"}

 

in my javascript I convert my json string into a PPS-encoded data field as described here 

 

http://developer.blackberry.com/cascades/documentation/device_platform/invocation/text_messages.html

 

I then call my C++ function to invoke the sms client

 

PS..  the code is messy as I have not cleaned it up.  going to make PPS encoding a seperate function.

 

Javascript:

 

                function sendSms( arg1 ) {
                    var obj = {"to":[arg1.NUMBER], "body":arg1.TEXT, "send":"false"};
                    var output = '', name, value;
                    for (name in obj) {
                        output += name + ':';
                        value = obj[name];
                        if (typeof value === 'string') {
                            output += ':' + value;
                        } else if (typeof value === 'number') {
                            output += 'n:' + value;
                        } else if (typeof value === 'boolean') {
                            output += 'b:' + value;
                        } else if (typeof value === 'object') {
                            output += 'json:' + JSON.stringify(value);
                        }
                        output += '\n';
                    }
                    _omnisWrapper.InvokeSms( output );   
                }

 C++

 

void BBOmnisWrapper::InvokeSms( QString data )
{
	InvokeManager *invokeManager = new InvokeManager(this);
	InvokeRequest request;
	request.setTarget("sys.pim.text_messaging.composer");
	request.setAction("bb.action.COMPOSE" );
	request.setMimeType("application/text_messaging");
	request.setData(data.toAscii());
	InvokeTargetReply *reply = invokeManager->invoke(request);
}