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
Posts: 10
Registered: ‎10-13-2011
My Device: 9900
My Carrier: T-mobile
Accepted Solution

How to invoke "Text Messages" app to compose sms from QML?

Hello, I'm trying to invoke the native app for sending sms, but can't figure out the invocation parameters.

 

There is docs about it at: http://developer.blackberry.com/cascades/documentation/device_platform/invocation/text_messages.html

 

I'm trying to do:

 

            attachedObjects: [

                Invocation {

                    id: invocation

                    query: InvokeQuery {

                        id: invokeQuery

                        invokeTargetId: "sys.pim.text_messaging.composer"

                        mimeType: "application/text_messaging"

                        onQueryChanged: invokeQuery.updateQuery();

                        

                    }

                }

            ]

            

            onTriggered: {

                //invokeQuery.data = ??? 

                invocation.trigger("bb.action.COMPOSE")

            }

 

But it's not working at all. Any suggestion is highly appreciated.

 

Thanks a lot,

Jan

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How to invoke "Text Messages" app to compose sms from QML?

Hi, I can't help you with the parameters not having done this, but one suggestion I have is to download and run the invokeclient sample app and experiment with changing the parameters in the app until you get the result you want then copy those across to your code.

 

Until someone answers this who's actually done this before I think this is a way to whittle down what's missing.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Retired
Posts: 249
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to invoke "Text Messages" app to compose sms from QML?

Hi,

I think you missed the action. Please specify the action as bb.action.COMPOSER (case sensitive).

 

For me, the following worked with the invoke client sample.

IMG_00000074.png

 

Please also note that with this specific invocation, if you wish to populate the to and body fields, you need to follow the guidelines exactly as specified in the docs page. I.e. you need to pps encode the data.

 

Shadid

Developer
Posts: 147
Registered: ‎05-31-2013
My Device: BlackBerry Z10 Limited Edition
My Carrier: Bonbon

Re: How to invoke "Text Messages" app to compose sms from QML?

[ Edited ]

Your screenshot shows the correct Invocation parameters.

However data itself is the issue in this question.

I do encode it to PPS with this:

function ppsEncode(obj) {
        var data = '',
            name,
            value;
        for (name in obj) {
            data += name + ':';
            value = obj[name];
            if (typeof value === 'string') {
                data += ':' + value;
            } else if (typeof value === 'number') {
                data += 'n:' + value;
            } else if (typeof value === 'boolean') {
                data += 'b:' + value;
            } else if (typeof value === 'object') {
                data += 'json:' + JSON.stringify(value);
            }
            data += '\n';
        }
        return data;
    }

 

Later on, further down the lines of code, I create this:

var obj = {
     "to": [ "0123456789" ],
     "body": "

 

", "send": false }; invokeQuerySMS.data = rootPage.ppsEncode(obj) invokeQuerySMS.updateQuery();

 

In Device Log, I can see that data has been transcoded into PPS format.

 

to:json:["0123456789"]
body::Blabla some text
send:b:false

 

 

But nothing happens. Card is not invoked. If no data is assigned, an empty card is invoked.

 

Thanks for helping out.

Retired
Posts: 249
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to invoke "Text Messages" app to compose sms from QML?

Is this a documented way of ppsEncoding strings in QML? The only safe way I know of is:

 

QByteArray encode (const QVariantMap &ppsData, bool *ok=0)

 

See examples here:

https://developer.blackberry.com/cascades/documentation/device_platform/invocation/phone.html

Developer
Posts: 147
Registered: ‎05-31-2013
My Device: BlackBerry Z10 Limited Edition
My Carrier: Bonbon

Re: How to invoke "Text Messages" app to compose sms from QML?

[ Edited ]

ppsEncode function in my previous post is borrowed from BB WebWorks. It is very minimal but  I haven't noticed any digression from bb:Smiley TonguepsObject::encode.

 

Following your suggestion of safe PPS encoding I whipped up a temporary converter function and exposed it to QML:

QByteArray ClipboardHandler::ppsEncode(QVariantMap map)
{
    return bb::PpsObject::encode(map, NULL);
}

 In QML, I pass this object into the function above:

var obj = {
     "to": [ "0123456789" ],
     "body": "Blabla some text",
     "send": false
};

 

and it produced this:

body::Blabla some text
send:b:false
to:json:["0123456789"]

 

End result remained the same. Card filled with data doesn't pop up. Smiley Happy

Visitor
Posts: 1
Registered: ‎05-28-2013
My Device: Z10
My Carrier: T-Mobile: bonbon

Re: How to invoke "Text Messages" app to compose sms from QML?

I seem to be having a very similar problem. I have also tried to pass number and message to C++ function that PPS encodes it and passes it back to QML Invocation. No luck.

I'm looking forward to evolution of this thread.

Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: How to invoke "Text Messages" app to compose sms from QML?

works perfect for me ;-)

 

in QML an ActionItem

onTriggered: {
     myApp.sendText("+4917955222","this is the body", false)
}

 

and in my app:

void ApplicationUI::sendText(const QString& sendTo, const QString& body,
		const bool sendNow) {
		InvokeRequest request;
		request.setAction("bb.action.COMPOSE");
		request.setTarget("sys.pim.text_messaging.composer");
		request.setMimeType("application/text_messaging");
		QVariantMap map;
		map.insert("to", QVariantList() << sendTo);
		map.insert("body", body);
		map.insert("send", sendNow);
		QByteArray requestData = bb::PpsObject::encode(map, NULL);
		request.setData(requestData);
		mInvokeManager->invoke(request);
}

 IMG_00000036.png

 

Smiley Happy

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: How to invoke "Text Messages" app to compose sms from QML?

as I understood from tweet, it works using the C++ way

please mark as solved

thx

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 147
Registered: ‎05-31-2013
My Device: BlackBerry Z10 Limited Edition
My Carrier: Bonbon

Re: How to invoke "Text Messages" app to compose sms from QML?

@ekke

Yes, C++ way works, thank you.

 

@Baran has found a working set of code for QML:

//Plucked out code snippet:
Invocation { query: InvokeQuery { invokeTargetId: "sys.pim.text_messaging.smsuri" mimeType: "*"
uri: "sms:0123456789?body=Blabla some text" } onArmed: { if (invokeQuerySMS.uri != "") { trigger("bb.action.OPEN"); } } }

 I can confirm both ways work so this thread can be closed as solved.