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
Developer
26filip
Posts: 224
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4
Accepted Solution

Headless, InvokeRequest and SmsTransport - reading message

[ Edited ]

Hello,

 

I have problem with reading content of SMS using headless part of my app.

 

I sent SMS using SmsTransport class:

MessageContact mc = MessageContact(1, MessageContact::To, phoneNr, phoneNr);

SmsTransport *smsT = new SmsTransport();

MessageBuilder *mb = smsT->createMessageBuilder();
mb->addAttachment(Attachment("text/plain", "", text));
mb->addRecipient(mc);

Message mm = *mb;

smsT->send(3585, mm);
debug.send("SMS sent", "SMS"); //this function inform me, that message was send

 This works, because it invoke headless part of my app:

void Service::handleInvoke(const bb::system::InvokeRequest & request) {
	if(request.action().compare("bb.action.PORT_DIRECTED_SMS")==0	{
		debug.send("Headless received SMS :)"); //this function inform me, that it works
	}
}

And here I register with port in UI part:

_smsTransport.registerPort(3585, "com.example.ST4FMSService");

 

Here from bar-descriptor:

<filter>
	<action>bb.action.PORT_DIRECTED_SMS</action>
	<mime-type>application/vnd.sms</mime-type>
	<property var="uris" value="data&colon;//local" />
</filter>

 

 

 But I don't know, how to read the content of message. Could you help me, please? :smileywink:

All time online :smileyvery-happy:
Please use plain text.
Developer
AricLam
Posts: 27
Registered: ‎11-07-2013
My Device: 9790
My Carrier: VietNam

Re: Headless, InvokeRequest and SmsTransport - reading message

why should you not use signal ?
Please use plain text.
Developer
26filip
Posts: 224
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: Headless, InvokeRequest and SmsTransport - reading message

I want to receive (and process them) when app is closed
All time online :smileyvery-happy:
Please use plain text.
Developer
26filip
Posts: 224
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: Headless, InvokeRequest and SmsTransport - reading message

Is it possible to read them trough headless or I need use signals? (which signals?)
All time online :smileyvery-happy:
Please use plain text.
Developer
smiley
Posts: 1,432
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: Headless, InvokeRequest and SmsTransport - reading message

Why don't you just use the MessageService class instead of using sms transporter?

 

Please use plain text.
Developer
26filip
Posts: 224
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: Headless, InvokeRequest and SmsTransport - reading message

If I good understand difference between SmsTransport and MessageService, Smstransport is only way to send messages without showing them in Hub - I send configuration and I don't want to show them to end-user...
All time online :smileyvery-happy:
Please use plain text.
Developer
smiley
Posts: 1,432
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: Headless, InvokeRequest and SmsTransport - reading message

you can delete it after the message is sent.

Please use plain text.
Developer
26filip
Posts: 224
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: Headless, InvokeRequest and SmsTransport - reading message

I can, but my customer don't want to hear/see anything :smileywink:

 

I found nice guide, but the most important method

bb::pim::message::Message message = bb::pim::message::SmsTransport::messageFromData(request.data(), &portNumber , &portNumber );

 is missing...

 

Please help me recognize, is it possible to read using InvokeRequest and SmsTransport or isn't?

 

(I really know other option, but unfortunately I'm interested only this one)

All time online :smileyvery-happy:
Please use plain text.
Developer
26filip
Posts: 224
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: Headless, InvokeRequest and SmsTransport - reading message

Happily, there is a solution to read SMS using request.data() :smileyhappy:

 

Thank you, Umer for help on Triggers documentation.

 

The solution is very easy:

QByteArray::fromBase64(request.data())

 it give a JSON object, which look like:

{
	"applicationPort":1234,
	"class":4,
	"encoding":"utf-8",
	"messageId":4745,
	"originatingApplicationPort":0,
	"path":1,
	"payload":"sample message",
	"receivedSegments":1,
	"senderAddress":" 48123456789",
	"serviceCenterTimeStamp":"1399284599000",
	"totalSegments":1
}

 

All time online :smileyvery-happy:
Please use plain text.