SMS listener

Hi - just wondering if he had plans to make available a way to implement a SMS listener for incoming SMS messages / outgoing (this was possible on the old Java SDK). I don't see anything equivalent in the latest SDKS, neither on the road map.

Thanks in advance :-)

Hello

in fact, we already support something very similar to the listeners of the Java platform.

SMS is part of the PIM API and the key classes

bb::pim::message::SmsTransport.

This class allows (among other things) registration for incoming SMS messages addressed to a specific port. You will receive SMS messages to port and be able to extract their payload as a byte array. The class uses Qt signals and slots, so it is quite easy to use. Here are a few snippets of code to help you get started:

in the header

public slots:
void onMessageReceived(unsigned int, const Message &);
void onRegisterResultReceived(unsigned int port, bb::pim::message::SmsTransportRegistrationResult::Type status );

private:
bb::pim::message::SmsTransport* _sms_transport;

in the source of the CPP, my class called SmsReceiver:

SmsReceiver::SmsReceiver(bb::cascades::Application *app) :
   QObject(app), _initialised_ok(false), _sms_transport(new bb::pim::message::SmsTransport(this)) {

    connect(_sms_transport, SIGNAL(registerResultReceived (unsigned int,
                    bb::pim::message::SmsTransportRegistrationResult::Type)), this,
                   SLOT(onRegisterResultReceived(unsigned int,
                                                                   bb::pim::message::SmsTransportRegistrationResult::Type)));

    connect(_sms_transport, SIGNAL(messageReceived (unsigned int, const Message &)), this,
                   SLOT(onMessageReceived(unsigned int, const Message &)));

    // registering to receive SMS messages addressed to port 16000
    _sms_transport->registerPort(16000);
}

void SmsReceiver::onRegisterResultReceived(unsigned int port, bb::pim::message::SmsTransportRegistrationResult::Type status) {

    if (status == 1) {
        log(QString("Port %1 registered OK").arg(port));
    } else {
        log("Failed to register port:" + status);
        log("Error:" + getResultReceivedName(status));
    }

}

void SmsReceiver::onMessageReceived(unsigned int port, const Message& message) {

  // the short_message payload is an Attachment to the PIM Message object and the .data() method returns it as a byte array
    bb::pim::message::Attachment attachment = message.attachmentAt(0);
    hexlog(attachment.data());

}

Key points:

  • registration will succeed or fail, and you must use the registerResultReceived signal to receive the notification of the result of this step.
  • When a message to your registered port is received by the operating system, a signal messageReceived sounds then you must connect one of your methods of this signal. Your slot will receive a Message object. The attribute short_message of the SMS ("short_message" by GSM 03.40) will be given an object attachment associated with the subject of the Message. Retrieves the attachment object and call the data() function to get short_message as a byte array. Note that to properly decode the array of bytes that you really know his what data_coding value has been used when you create and send the SMS message and whether or not a header (UDH) user data is present.

I hope this helps.

Martin

Tags: BlackBerry Developers

Similar Questions

  • How to test the SMS listener using 2 emulators in SDK5 running Windows 7

    Hi all. Writing a SMS listener I want to test. But can someone please pass me how I can configure the SDK BB 5 (not the Eclipse plugin) running on Windows 7, so that I can send a test SMS from an emulator to another to see what is happening in the debugger. Thank you so much as always.

    Found answer in another post from Kanaksony. His response has been to make the source and destination for even 1 emulator ports. His post was:

    You need to sms-source port and sms-destination ports even in Simulator. Go to JDE-> Edit-> preferences-> tab-> port sms-source Simulator: 21316 and port destination sms: 21316

  • -Contact SMS listener?

    Hi all

    I put in place of the SMS listener and I am able to get the device number but I'm not able to get the name of the contact to shippers. Any one know how to get contact name of entrants and SMS-password.

    Thank you

    got the solution here:- recover contacts by phone number

  • SMS for outgoing SMS listener throws IOException immediately after the open call

    I had already created a class for sending SMS messages which worked perfectly until I added the listener. When the listener is added as soon as I start the thread throws an IOException exception who am I hurting? The only thing I can think is some kind of wire problem, please help.

    Here's the SMS & Listener class:

    private static final class SmsMessage    {        private String _address;        private String _msg;
    
            public SmsMessage(String address, String msg)        {            _address = address;            _msg = msg;        }
    
            public Message toMessage(MessageConnection mc)        {            TextMessage m = (TextMessage)mc.newMessage(MessageConnection.TEXT_MESSAGE,"sms://" + _address);            m.setPayloadText(_msg);            return m;        }    } // SmsMessage
    
       private final class SendThread extends Thread    {        private static final int TIMEOUT = 500; // ms        private Vector _msgs = new Vector(10); // Queue of 10        private volatile boolean _start = false;
    
            // queue requests        public synchronized void send(String address, String msg)        {            _start = true;            _msgs.addElement(new SmsMessage(address, msg));        }
    
            public synchronized void stop()        {            _stop = true;            try {                if ( _mc != null ){                    _mc.close();                }            } // catch (IOException e ) {                catch (Throwable t) {                t.printStackTrace();                System.exit(0);            }
    
            }
    
            public void run()        {            try {                //closed by the stop() method                _mc = (MessageConnection)Connector.open("sms://");
    
                    if (_mc != null)                {                    // set a listener to trap outgoing sms messages                    _mc.setMessageListener(new OutboundSMSListener());                }                for(;;)                {                    while( !_start && !_stop)                    {                        try {                            sleep(TIMEOUT);                        } // catch (InterruptedException e) {                            catch (Throwable t) {                                t.printStackTrace();                                System.exit(0);                            }                    }                    if ( _stop )                    {                        return;                    }
    
                        while(true)                    {                        try {                            SmsMessage sms = null;                            synchronized (this)                            {                                if ( !_msgs.isEmpty() )                                {                                    sms = (SmsMessage)_msgs.firstElement();                                    // take it out of the queue once we sent it                                    _msgs.removeElement(sms);                                }                                else                                {                                    _start = false;                                    break;                                }                            }
    
                                _mc.send(sms.toMessage(_mc));
    
                            } // catch (IOException e) {                            catch (Throwable t) {                                t.printStackTrace();                                System.exit(0);                        }                    }                }            } // catch (IOException e)              catch (Throwable t) {                t.printStackTrace();                System.exit(0);              }        }    } // SendThread
    
        private static final class OutboundSMSListener implements OutboundMessageListener    {        public void notifyIncomingMessage(MessageConnection messageconnection)        {            // we don't care about incoming sms messages right now        }
    
            public void notifyOutgoingMessage(Message message)        {            Dialog.alert("Detected An Outgoing SMS Event");        }    }
    

    Thank you. Makes sense.

  • SMS listening by using Cascades SmsTransport

    I'm having some trouble with the SmsTransport api. The listeners for phone and email are simple and work great, but when I try and listen for sms I get this runtime warning:
    
    Warning: Object::connect: No such signal bb::pim::message::SmsTransport::messageReceived(unsigned int, const
    bb::pim::message::Message&) in ../src/App.cpp:58
    
    and this is the code that is the problem:
    
         mSmsTransport->registerPort(0);
         connect(mSmsTransport, SIGNAL(messageReceived(unsigned int, const bb::pim::message::Message&)), SLOT(handleSms(unsigned int, const bb::pim::message::Message&)));
    
    Maybe the method signature has changed from what is listed here?
    https://developer.blackberry.com/cascades/reference/bb__pim__message__smstransport.html
    
    Also related to this.. is 0 the correct port to register on to listen for SMS's? It worked this way on Java BB but I'm not sure about BB10.
    

    Patch the SDK to C:\devel\bbndk\target_10_0_9_2318\qnx6\usr\include\bb\pim\message\MessageUpdate.hpp and adding the line to the bottom of the file solves the problem. Not sure how it works for you, unless you have this line.

    Q_DECLARE_METATYPE (bb:im::message:MessageUpdate)

  • incoming SMS listener test

    Hi all. Writing a listener SMS coming that I want to test. But can someone please pass me how I can configure the SDK BB 5 (not the Eclipse plugin) running on Windows 7, so that I can send an SMS to test an emulator to another to see what is happening. Thank you so much as always.

    Found answer in another post from Kanaksony. His response was to use 1 emulator with the following:

    You need to sms-source port and sms-destination ports even in Simulator. Go to JDE-> Edit-> preferences-> tab-> port sms-source Simulator: 21316 and port destination sms: 21316

  • Running the background (sms listening thread) connected to the GUI (another point of entry) application thread

    Hi, I'm new to the development of Blackberry, I read everything on the application running at startup and have a different point of entry for this application. I still need help with my application

    I use BB JDE 4.7

    Simulator: BB 9530 4.7.0

    I'm developing an application of SMS. (extends UiApplication)

    1) there is a thread that listens for incoming messages

    2) there is a wire which is a SMS sender

    3) there is a main screen and two full screens. for example, when the user clicks a button in one of the screens full... I send you a message

    (4) when a message is received, based on the content of the message I push either a full screen

    (5) I have, all the wires and screens as the class internal to the main class that extends from the UiApplication.

    I got the basic features. I need help making that demand the application of autostartup

    (1) I need to start listening to the sms thread when the BB phone starts

    (2) I need to have the application icon in the applications screen as another entry point for the application (only for the GUI), and the listening thread must remain active in the background.

    (3) when an incoming message is detected, the application GUI should be brought to the foreground (if it isn't already forground) after posting a popup (instead of bring the application to the foreground, is it better to display a flashing icon in the status bar of the home screen blackberry and perhaps global popup)

    (4) when the GUI of the application part is closed, I need to stop the sms sending thread, and when the system shuts down, I need to stop the listening thread.

    Please help me guys... I have read many articles and discussions regarding the automatic start-up of applications, another point of entry, the # of background threads...

    but I couldn't find how to implement my needs.

    (1) should I need to create two different projects (applications [GUI thread, a sender] and one for the listening thread)? or I can achieve in single application?

    (2) should I have to sign in the background thread to the GUI app? If so, how?

    (3) it is necessary to use the RunTimeStore object? If so, I don't know how I can bring to the foreground the application GUI of the background thread.

    (4) if I have to stop the thread of listening by overiding onExit() method, the important question I have is, if the onExit() method is only for applications that extends from the Application class and not for the UiApplication class?

    (5) if I should have two projects (one main and the other as a spare point entry), which project should I do as "autorun at startup" and a "system module".

    As I need to have the background still running thread when the GUI application is active. I don't know how I do.

    Hello world...

    I reached my needs thanks to a single application. I used an other entry point.

    To refer to chk my other post

    http://supportforums.BlackBerry.com/T5/Java-development/how-to-avoid-creating-two-instances-of-the-a...

  • How to receive and send SMS in the emulator or Simulator?

    Hello

    I am newbie to blackberry. I want the code to send and receive SMS listener in the emulator or Simulator.

    the research would have helped you a lot here.

    http://supportforums.BlackBerry.com/T5/Java-development/different-ways-to-listen-for-SMS-messages/TA...

    http://supportforums.BlackBerry.com/T5/Java-development/use-SMS-to-notify-an-application/Ta-p/444965

    in particular with regard to the Simulator:
    http://supportforums.BlackBerry.com/T5/Java-development/simulate-phone-call-amp-message/m-p/138303?q...

  • Question red watch SMS Simulator

    Hi all, using 2 9700 simulators under version 5 to try and test a SMS listening program. This used to work fine, but now whenever I have try and send an SMS from 1 Simulator to another, I get a red clock next to the SMS sender and I never get anything else. Like I said it worked very well. The 2nd Simulator runs from a different location than iis used during debugging. I've played around with the SMS settings (currently packs turns to 7-bit encoding) with no joy. Also shot and manage connections without joy. Mobile network take their flight simulator and data services are turned on.

    Can someone tell me what I should do to fix this please because the reset does not work either. Thanks a lot for any assistance.

    Try resetting the simulator by running the clean.bat file located in the directory of Simulator.

    If this does not help, make sure that you do not have any firewall software that blocks the ports used to send and receive SMS messages.

  • Listener is the addition of several times

    Hello

    My app account number of messages send by user for this I wrote to count the messages app. I did it using sms listener concept, but the problem is listener sms adding several times. Whenever I start the app it adds a listener most. Anyone has idea how to add sms listener only once?

    Please help me on this

    RuntimeStore runtimeStore = RuntimeStore.getRuntimeStore();
    if( runtimeStore.get(MYKEY) == null ) {
       MyListener myListener = new MyListener();
       runtimeStore.put(myListener,MYKEY);
    } else {
       MyListener myListener = (MyListener)runtimeStore.get(MYKEY);
    }
    
  • SMS port already in use... MessageConnection using connector.open

    I created an application that listens for incoming txt messages and it works very well on all devices except the 8330... works of ideal app on all phones on sms listening but on the 8330 I get the problem where the exception says "port already in use"... my application is currently in beta and a user reported he was continues smart guard... as soon as he took the chip guard the app works perfectly... so im guessing as smart guard uses sms messages to intitate itself is what is the origin of the port problem... is there anyway around this? my code is below...

    public void open()
        {
            this.controller.write("Attempting to open message connection (Message tracker)");
            try {
                this.msgconnection=(MessageConnection)Connector.open("sms://:0");
            } catch (IOException e) {
                this.controller.writeToConsole("Error opening message Connection (MessageTracker) "+e.getMessage());
            }
            try {
                if(this.msgconnection!=null)
                {
                this.msgconnection.setMessageListener(this);
                }
            } catch (Exception e) {
                this.controller.writeToConsole("Error adding messagelistner (MessageTracker) "+e.getMessage());
            }
        }
    

    MessageConnection is pretty useless, since only one application can attach to the SMS port at a time.

    My advice is to switch to use the method of datagram.

    See this article:

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

  • Test MessageListener

    Hey guys,.

    I'm writing a SMS listener for the blackbery using MessageListener. The code I use is from this page. The question I have is that I'm unaware of an appropriate way to test this. Because I am not allowed to run two simulators at the same time I can't simulate sending an SMS. Now, I'm sure that there is a way to make it so I came for the experts!

    I'm doing my development using the Eclipse Plugin of the RIM. If you need more information, I would be happy to provide it.

    -Fnab

    OK, if your current running on the same localhost, you must use the following command
    NC u 127.0.0.1 4000<>

    Before that, run a nestat to ensure you port 4000 is listening.
    BTW, udp nc stop normally. Its normal.
    Good luck

  • Earphone for texting on blackberry

    I've implemented background application.

    I used below the code tuned for receiving text messages. Its works perfectly.

    But unable to listen to the sms sent. I check with "_dc.send (d)" but his throw IOFormat exception.

    How to listen to send sms background application?

    The code for receiving sms listening:

    private class ListeningThread extends Thread
        {
            private boolean _stop = false;
            private DatagramConnection _dc;
            public void run()
            {
                try
                {
                    _dc = (DatagramConnection)Connector.open("sms://");
                    for(;;)
                    {
                        if ( _stop )
                        {
                            return;
                        }
                        Datagram d = _dc.newDatagram(_dc.getMaximumLength());
                        _dc.receive(d);
                        String address = new String(d.getAddress());
                        String msg = new String(d.getData()); 
    
                    }
                } catch (IOException e) {
                    System.err.println(e.toString());
                    DialogUtil.showDialog("Exception: Listen sms: \n"+e);
                }
            }
        }
    

    I suggest
    http://www.BlackBerry.com/developers/docs/7.1.0api/NET/RIM/BlackBerry/API/SMS/SMS.html#addSendListen...

  • Porting, which is developed in BB JDE 4.7 in Blackberry Torch

    Hello

    I put a BB JDE 4.7 application

    I tested the app in the Simulator 4.7.0

    The application has a basic user interface (buttons, choice fields, change fields and three screens and pop-up windows)

    It is an application to send and receive messages of Type 0.

    He has two sons and the main UI thread.

    right now I'm working on auto execute the part of demand (sms listener).

    I intend to move the Blackberry Torch device soon

    Question 1: know if I can port the same application that is developed using BB JDE 4.7 in Blackberry torch? Is it necessary to download BB JDE 6.0 to develop for Blackberry Torch?

    Question 2:  If I can use the same application and even BB JDE 4.7, if I can still use Blackberry device Simulator 6 as well as the BB JDE 4.7 version?

    Question 3: What are the complications I have got to face the passage to BB JDE 6.0?

    an application developed in 4.7 (with touch user interface in mind) should run on the torch without any problem.

    You can download a torch Simulator to test if you do not have a real device.

  • empty text message to certain provider

    Hi people, I use a sms listener widely documented in my application:

    public void run() {}

    try {}

    _DC = ("DatagramConnection)Connector.open("sms://: ");

    for(; ) {

    If {(_stop)

    return;

    }

    Datagram d = _dc.newDatagram (_dc.getMaximumLength ());

    _DC. Receive (d);

    Address of the string = new

    String (d.GetAddress ());

    String msg = new String (d.getData ());

    System.out.println ("message:" + msg);

    System.out.println ("to:" + address);

    }

    It works very well for texts normal phones, but when I receive a message from Clickatell message is always empty even if when I go to the Inbox of the message is there with all the text. Any ideas why it does this?

    The other odd thing is that the Message received: to: print on the same line, when the message is empty, but on separate lines when the message has something.

    I was debugging for Age but no joy so any help much appreciated.

    It turns out that this is a problem of Unicode, it does not seem like trying to read Unicode text messages...

Maybe you are looking for

  • Satellite C70 - A - 14 M - stange problem with touchpad

    Hello I'm having a problem of stange with the keyboard of my Toshiba Satellite C70 - A - 14 M.After a few seconds the start menu/desktop automatically load up, the functionality of the touchpad goes in the normal cursor to free movement only by selec

  • Passable on Win XP

    Track running on Win XP. HP Elite computer with LARGE screen TV with an HDMI cable. Computer came with Windows 7.  Disorders, thought it was the system.  Restored 7 sometimes rebuilt drive with 7, rebuilt drive with XP and then made sure that Direct

  • Recently burned CD not recognized by several cd players

    Since I got my Dell computer (several years), I have burned many cd successfully.  The only problem I've had in the past was Windows Media to get the names of the titles of the albums/songs.  I tried to fix it but failed and he gave up. Everything I

  • Add words to the spelling check

    Hotmail Compose E-mail: Language: Portuguese Spell Checking tip the misspelled word, but does not offer the correct spelling I have it correct me and click "add to Dictionary". Hotmail does not add to it. On my next text, when I made the same mistake

  • am having problem downlaoding

    When installing SP 1, on my Windows vista I moved my files and program in a new folder. I then intall SP 1 in a new window and the old folder called old window in the hard drive of my computer. How can I download or reinstall some of these programs o