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
Regular Contributor
Posts: 75
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile
Accepted Solution

Empty Sender and MimeType for received SMS

I read the guide to read incoming sms here:

 

http://supportforums.blackberry.com/t5/Native-Development-Knowledge/BlackBerry-10-Developer-s-Guide-...

 

I'm able to catch the signal with a slot method but when i try to read the SMS type or sender I get an empty string.

The code is:

void MyClass::messageReceived(bb::pim::account::AccountKey AccountID , bb::pim::message::ConversationKey ConversationID , bb::pim::message::MessageKey MessageID)
{
    bb::pim::message::Message ReceivedMessage;
    bb::pim::message::Attachment MessageAttachment;
    QString MessageText;
    QString LoginPassword;

    Logger::writeLog("Received Message\n");

    ReceivedMessage = MessageServiceHandler.message(AccountID , MessageID);

    if(true)//message.mimeType().compare(bb::pim::message::MimeTypes::Sms) == 0)
    {
        Logger::writeLog("Message Type: %s\n" , ReceivedMessage.mimeType().toAscii().data() );

        if(true)//message.isInbound() == true)
        {
            Logger::writeLog("Sender: %s\n" , ReceivedMessage.sender().displayableName().toAscii().data() );

            if(ReceivedMessage.sender().displayableName().contains("<expected number>") == true)
            {
                Logger::writeLog("Received SMS from %s\n" , ReceivedMessage.sender().displayableName().toAscii().data() );

 I've also tried to take the account id by the AccountService insted of passing that I receive from the signal (). The result is ever the same. The ouput is just:

Received Message

Message Type:

Sender:

 
Is there something wrong ?



Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Empty Sender and MimeType for received SMS

Hi

 

I can't see anything obviously wrong. Could you also post your connect statement (for the signal/slot) and your MessageServiceHandler method too please?

 

What device and OS version are you testing on?

 

When you send your inbound message, does it get stored in the text messages "inbox"?

 

I'll see if I can help.

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Regular Contributor
Posts: 75
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile

Re: Empty Sender and MimeType for received SMS

Thank you for the answer.

 

I'm using a Q5 device with OS version 10.2.0.210. The API level is set to 10.2.

 

This is the MessageServiceHandler variable:

 

        bb::pim::message::MessageService MessageServiceHandler;

 and this is the connection to the signal:

 

    if(connect(&MessageServiceHandler , SIGNAL(messageAdded(bb::pim::account::AccountKey , bb::pim::message::ConversationKey , bb::pim::message::MessageKey) ) , this , SLOT(messageReceived(bb::pim::account::AccountKey , bb::pim::message::ConversationKey , bb::pim::message::MessageKey) ) ) == false)
    {
        Logger::writeLog("***WARNING*** Cannot connect to MessageAdded() signal\n");
    }
Regular Contributor
Posts: 75
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile

Re: Empty Sender and MimeType for received SMS

I don't know if useful but the number of the sender is not saved in the contacts list of the phone. And the BlackBerry ID is not configured on the phone.

 

I've also tried this code on the same slot method:

 

	int size;

	QString MessageText;
	QString LoginPassword;

	Message ReceivedMessage;
	Attachment MessageAttachment;
	MessageFilter filter;
	Account MessagesAccount;
	QList<Message> MessageList;
	QList<Conversation> ConversationList;

	Logger::writeLog("Received Message\n");

	MessagesAccount = AccountServiceHandler.defaultAccount(Service::Messages);
	filter.insert(MessageFilter::Quantity ,QVariant("1") );

	MessageList = MessageServiceHandler.messages(MessagesAccount.id() , filter);
	ConversationList = MessageServiceHandler.conversations(MessagesAccount.id() , filter);

	size = MessageList.size();
	Logger::writeLog("Messages: %d\n" , &size);
	size = ConversationList.size();
	Logger::writeLog("Conversations: %d\n" , &size);

 The result was:

 

Received Message

Messages: 0

Conversations: 0

 Seems like I have no access to the Message box.

Received Message

Messages: 0

Conversations: 0

Developer
Posts: 222
Registered: ‎05-21-2012
My Device: BlackBerry RED Z10
My Carrier: WiFi

Re: Empty Sender and MimeType for received SMS

You can't retrieve a sender name if there are no messages in the list. So I suggest you try to remove the filter in your code?

Regular Contributor
Posts: 75
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile

Re: Empty Sender and MimeType for received SMS

I can't do that. The filter is mandatory for that method and I don't think It can be the problem. The filter just filters for quantity and removing the "insert" line doesn't change the result.

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Empty Sender and MimeType for received SMS

Can you please install my SmsMessageService application and see if it works on your device please? At least if it works we'll know that the issue is in your code somewhere:

 

https://github.com/blackberry/Cascades-Community-Samples/tree/master/SmsMessageService

 

Thanks

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Regular Contributor
Posts: 75
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile

Re: Empty Sender and MimeType for received SMS

I've tried your sample and it seem to work correctly. I've sent an SMS to the BB and number and body of the message is correctly appeared. 

I'll take a look on your sample to find out what's wrong in mine.

I'll keep you up to date.

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Empty Sender and MimeType for received SMS

OK, tht's a good step forward then. Looking forward to hearing what you discover.

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Regular Contributor
Posts: 75
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile

Re: Empty Sender and MimeType for received SMS

I solved quickly adding a missing permission on the bar-descriptor.xml file.
I don't remember what was missing but was one of these:

 

<permission system="true">run_native</permission>
<permission>access_pimdomain_messages</permission>
<permission>access_sms_mms</permission>
<permission>access_phone</permission>

 These are the permissions in the bar-descriptor.xml file of the SmsMessageService sample app.