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
Posts: 105
Registered: ‎09-06-2013
My Device: Z10
Accepted Solution

[PIM Messages] SMS Msg Recipient nameless

As subject title , 

 

Example, my sim card number is 11223344, i received sms from 777777.

 

The sender name puts 777777 which is correct

 

However the recipient list i retrieved using message.recipients which I then looped through to get the recipient name is empty?

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

Re: [PIM Messages] SMS Msg Recipient nameless

Could you share your code please?

 

What device model (from Settings-About) are you using and what OS version?

 

Thank you

--------------------------------------------------------------------------------------------
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
Developer
Posts: 105
Registered: ‎09-06-2013
My Device: Z10

Re: [PIM Messages] SMS Msg Recipient nameless

My dev machine does not have internet so here is roughly the code part.

 

My original code was somewhat based on the guide to SMS.

 

One more note, the Conversion::mimeType() method returns an empty QString too

 

Code in brief : 

 

  1. Grab sms account
  2. Grab conversationkeys using accountkey
  3. loop each conv key for messageslist
  4. for each msg list, loop each message

Mimetype check for sms works for Message::mimeType() but not Conversation::mimeType

 

Code : 

...

//Filter empty
MessageFilter filter;

AccountKey accountKey = m_accountService->accounts(Service::Messages, "sms-mms").first().id();

foreach (ConversationKey convKey, m_messageService->conversationKeys(accountId,filter)) 
{
    QList<Message> msgList = m_messageService->messagesInConversation(accountId,convKey,filter);

    Conversation conv = m_messageService->conversation(accountId,convKey);

    qDebug() << conv.mimeType() //empty QString

    foreach (Message msg, msgList) {
        if (msg.mimeType == MimeTypes::Sms)
        {
            if(msg.attachmentCount > 0){ 
                if (msg.isInbound){
                    qDebug() << msg.sender().displayableName(); 
                    //shows      777777 (example)
                    foreach (MessageContact msgContact, message.recipients) {
                         qDebug() << msgContact.displayableName();                   
                        //shows empty qString (example)
                    }
                }
            }
        }
    }
}

 Another side question , if 777777 exists as one of my contacts as name = John , the displable name shows John and not the number, how do I get the 777777 and also John in that case. 

 

Initially I wanted to check if the conversation mime is sms, if not, I will safe some ticks by not retrieveing the messages at all. Couldnt figure out why recipient is empty for incoming

 

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

Re: [PIM Messages] SMS Msg Recipient nameless

And what device model (from Settings-About) are you using and what OS version?

 

I need this so I can investigate against the same device and build as you. Thanks.

--------------------------------------------------------------------------------------------
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
Developer
Posts: 105
Registered: ‎09-06-2013
My Device: Z10

Re: [PIM Messages] SMS Msg Recipient nameless

So sorry I can only comfirm its a Z10 currently, not sure about its build. 

 

PS : Its a company device, I think i can only double check after the weekend

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

Re: [PIM Messages] SMS Msg Recipient nameless

OK, let me know when you can :-)

 

I'll take a closer look at your code on a 10.2 Z10 later today.

 

Have a nice weekend.

--------------------------------------------------------------------------------------------
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
Developer
Posts: 105
Registered: ‎09-06-2013
My Device: Z10

Re: [PIM Messages] SMS Msg Recipient nameless

Oh s*** , so sorry, I meant Q10(the one with a hardware keyboard), accidentally typed the all touch screen variant. :Oops:

 

Thanks! You have a nice weekend too! :Rockon:

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

Re: [PIM Messages] SMS Msg Recipient nameless

OK Q10 it is then :-)

--------------------------------------------------------------------------------------------
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
Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10

Re: [PIM Messages] SMS Msg Recipient nameless

Here's some code I used just now to investigate:

 

void SmsMessageService::messageReceived(bb::pim::account::AccountKey account_key, bb::pim::message::ConversationKey conv, bb::pim::message::MessageKey message_key) {

	qDebug() << "XXXX messageReceived";

	Message message = _message_service->message(_sms_account_id, message_key);

	qDebug() << "XXXX Message mime type:" << message.mimeType();
	if (message.mimeType() == MimeTypes::Sms) {
		qDebug() << "XXXX messageReceived: It's an SMS!!!";
		if (message.isInbound()) {
			qDebug() << "XXXX sender:" << message.sender().displayableName();
			if (message.attachmentCount() > 0) {
				showToast("SMS received");
				bb::pim::message::Attachment attachment = message.attachmentAt(0);
				log(QString("RCVD: SMS\n").append("RCVD: from " + message.sender().displayableName()).append("\nRCVD: ").append(QString(attachment.data())));
                log(QString("displayableName:" + message.sender().displayableName()));
                log(QString("name:" + message.sender().name()));
                log(QString("address:" + message.sender().address()));
			} else {
				qDebug() << "XXXX messageReceived: no attachments";
			}
		} else {
			qDebug() << "XXXX messageReceived: not inbound";
		}
	}  else {
		qDebug() << "XXXX messageReceived: not an SMS";
	}
}

I sent an SMS from device B to the device running a modified version of my SmsMessageService app with the above code. Call that device A.

 

On device A I had an entry in the Contacts app for hte phone number of device B.

 

These three lines:

                log(QString("displayableName:" + message.sender().displayableName()));
                log(QString("name:" + message.sender().name()));
                log(QString("address:" + message.sender().address()));

 gave the following results:

 

displayableName: first name + " " + last name with values from the Contacts entry. e.g. Fred Smith

name: same as displayableName

address: device B phone number

 

I then deleted the entry from the Contacts database and tested again. All three fields of interest now contain the sender's phone number.

 

So it looks like if the number is in the address book / Contacts app with the name fields filled in then displayableName and Name will be derived from the first name and last name in the Contacts app and address will be the sender phone number. Otherwise, all three of name, displayableName and address will contain the sender's phone number.

 

Hope that solves your problem.

 

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
Developer
Posts: 105
Registered: ‎09-06-2013
My Device: Z10

Re: [PIM Messages] SMS Msg Recipient nameless

Thanks! Any update on recipient info for incoming message?