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: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Message listener on headless not working

im trying to create a listener on headless. its not working for me. i get the code from SmsMessageService

 

here is the code

SMSListener.cpp

/*
 * SMSListener.cpp
 *
 *  Created on: 20 Mei 2014
 *      Author: anditsung
 */

#include "SMSListener.hpp"

#include <bb/Application>
#include <bb/pim/account/Provider>
#include <bb/pim/account/Result>
#include <bb/pim/message/MessageService>
#include <bb/pim/message/Message>
#include <bb/pim/message/MessageBuilder>
#include <bb/pim/message/ConversationBuilder>
#include <bb/pim/message/Keys>
#include <bb/pim/message/StatusReport>
#include <bb/pim/message/MessageUpdateType>
#include <bb/pim/message/MimeTypes>

using namespace bb::pim::account;
using namespace bb::pim::message;

SMSListener::SMSListener(bb::Application *parent)
    : QObject(parent), mInitialised_ok(false), mSMSAccountId(0)
{
    mAccountService = new AccountService();
    mMessageService = new MessageService();

    connect(mMessageService, SIGNAL(messageAdded(bb::pim::account::AccountKey, bb::pim::message::ConversationKey, bb::pim::message::MessageKey)), SLOT(messageReceived(bb::pim::account::AccountKey, bb::pim::message::ConversationKey, bb::pim::message::MessageKey)));

    connect(mMessageService, SIGNAL(messageUpdated(bb::pim::account::AccountKey, bb::pim::message::ConversationKey, bb::pim::message::MessageKey, bb::pim::message::MessageUpdate)), SLOT(messageUpdated(bb::pim::account::AccountKey, bb::pim::message::ConversationKey, bb::pim::message::MessageKey, bb::pim::message::MessageUpdate)));

    qDebug() << "XXXX getting SMS-MMS account";
    QList<Account> AccountList = mAccountService->accounts(Service::Messages, "sms-mms");
    mSMSAccountId = AccountList.first().id();
    qDebug() << "XXXX got SMS-MMS account. id=" << mSMSAccountId;

}

SMSListener::~SMSListener(){

}

void SMSListener::messageReceived(bb::pim::account::AccountKey account, bb::pim::message::ConversationKey conv, bb::pim::message::MessageKey message) {
    qDebug() << "XXXX messageReceived";
}

void SMSListener::messageUpdated(bb::pim::account::AccountKey account, bb::pim::message::ConversationKey conv, bb::pim::message::MessageKey message, bb::pim::message::MessageUpdate update) {
    qDebug() << "XXXX messageUpdated";
}



 

SMSListenerr.hpp

#ifndef SMSListener_HPP_
#define SMSListener_HPP_

#include <QObject>
#include <bb/pim/account/AccountService>
#include <bb/pim/account/Account>
#include <bb/pim/message/Keys>
#include <bb/pim/message/MessageUpdate>

namespace bb { class Application; }
namespace bb { namespace pim { namespace account {class AccountService; class Account; }}}
namespace bb { namespace pim { namespace message {class MessageService; class MessageBuilder; class Keys; class MessageUpdate; }}}

class SMSListener : public QObject
{
    Q_OBJECT
public:
    SMSListener(bb::Application *parent = 0);
    virtual ~SMSListener();

public slots:
    void messageReceived(bb::pim::account::AccountKey account, bb::pim::message::ConversationKey conv, bb::pim::message::MessageKey message);
    void messageUpdated(bb::pim::account::AccountKey account, bb::pim::message::ConversationKey conv, bb::pim::message::MessageKey message, bb::pim::message::MessageUpdate update);

private:
    bb::pim::account::AccountService* mAccountService;
    bb::pim::message::MessageService* mMessageService;
    int mSMSAccountId;
    bool mInitialised_ok;
};

#endif

 i cannot see the qdebug at all..

how do i know the headless is running?

 

 

 

 

 

Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: Message listener on headless not working

Nobody can help????

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

Re: Message listener on headless not working

Is your app a long running headless application or does it use headless triggers?

 

If long running then you can check whether or not your headless service is running as follows. Plug your BlackBerry 10 device into USB. Start Momentics. Go to the QNX System Information perspective. Right click on your device in the Target Navigator panel and select Launch SSH session. Execute the command "pidin", optionally piping its output into a grep command that will filter on your application headless name. Run without filter first just to be safe. You should see your service in the process list. If you do not then it is not running.

 

If it is a long running headless service and it is not running then it may have crashed.

 

cd /accounts/1000/appdata

 

Then cd to the directory containing your app (ls to check the names). Then cd to logs. Run ls -l. Do you see any .core files? If so, copy them off the device using Momentics Target File System Navigator and use Post Mortem Debugging to find out what went wrong.

 

Hope this helps

 

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: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: Message listener on headless not working

i can see the progress is runing but i dont see any .core files.

maybe its working but not intercepting messages. do i need to add the permission foraccess_sms_mms on the headless?i dont see the decription-bar.xml. where i can add it?

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

Re: Message listener on headless not working

OK so the headless service is running and not crashing.

 

I suggest you move your code to a GUI and test it there first before trying it in a headless service. Just create a really simple GUI app and check that it can intercept SMS messages. It may be something simple not related to "headless" at all.

 

Meanwhile I'll check whether there are any special considerations regarding use of MessageService in this way in a headless app.

 

You didn't answer my question but it sounds like you have a "long running" headless app rather than one set to use triggers, correct?

--------------------------------------------------------------------------------------------
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: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: Message listener on headless not working

[ Edited ]

just now aready try the same code on the UI part and it working fine, i can intercept the message. but on the headless part i cant see anything on it.

 

yes this will be a long running. since there is no trigger for sms right?

 

Edit: i mean sms direct port trigger

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

Re: Message listener on headless not working

OK, thanks for confirming. I've sent some questions to the development team responsible for MessageService and will get back to 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: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: Message listener on headless not working

thanks for the help
Developer
Developer
Posts: 24
Registered: ‎05-14-2014
My Device: Blackberry-Z10
My Carrier: Vodafone

Re: Message listener on headless not working

Hi,

 

I have created a headless app for messageservice. It works for me. That is when a new message, email, PIN message is received it fires the signal (messageAdded) and then the corresponding slot function is fired.

But for headless apps you need to use IDE 10.2 and SDK 10.2.

Also in the .pro files of the headless part of the app I have added the following lines LIBS += -lbb -lbbsystem -lbbplatform -lbbdata -lbbpim  QT += sql declarative QT += xml.

I have issue with messagesAdded signal. It fires the signal but does not connect to the slot function.