BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-14-2008, 02:09 PM   #1 (permalink)
New Member
 
Join Date: Aug 2008
Model: Curve
PIN: N/A
Carrier: T-Mobile
Posts: 13
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Programatically Detecting a SMS Sent

Please Login to Remove!

Is there a way to be notified of a text message being sent from the device. Registering for a change event for the sent folder or something similar for a text message not an email.
Offline  
Old 11-14-2008, 03:22 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

Read the API docs for OutboundMessageListener
Offline  
Old 11-14-2008, 03:25 PM   #3 (permalink)
New Member
 
Join Date: Aug 2008
Model: Curve
PIN: N/A
Carrier: T-Mobile
Posts: 13
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sounds perfect, thanks for your response.
Offline  
Old 11-30-2008, 03:43 PM   #4 (permalink)
New Member
 
Join Date: Aug 2008
Model: Curve
PIN: N/A
Carrier: T-Mobile
Posts: 13
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Adding SMS Listener throws IOException

I had previously created a class to send SMS messages that had been working perfectly until I added the listener. When the listener is added as soon as I start the thread it throws an IOException what am I doing wrong ?

Code:
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");
        }
    }
Offline  
Old 12-02-2008, 02:59 PM   #5 (permalink)
New Member
 
Join Date: Dec 2008
Model: 8700
PIN: N/A
Carrier: AT&T
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Joel, I am creating a similar application. I am not sure why you're getting an exception. I suggest debugging it on the device.

On another note, have you figured out how to store the sent message in the Sent folder?
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Ole Henriksen Blue Black Berry Enzyme Facial Mask, 3.5 Fluid Ounce
$19.99
Ole Henriksen Blue Black Berry Enzyme Facial Mask, 3.5 Fluid Ounce picture16 cans ZEP Meter Mist POWDER FRESH FRENCH VANILLA FRESH LINEN BLACKBERRY
$64.99
16 cans ZEP Meter Mist POWDER FRESH  FRENCH VANILLA  FRESH LINEN BLACKBERRY pictureblackberry 3.5mm stereo Headset HDW-15766-005 for 9900 9780 9000 9700 9800 9930
$4.99
blackberry 3.5mm stereo Headset HDW-15766-005 for 9900 9780 9000 9700 9800 9930 pictureUNLOCK CODE AT&T USA BLACKBERRY Torch 9800 9810Unlock Code out of contract only
$1.99
UNLOCK CODE AT&T USA BLACKBERRY  Torch 9800 9810Unlock Code out of contract only pictureBLACKBERRY UNLOCK CODE AT&T USA BLACKBERRY TORCH 9800/ 9810/9860
$1.99
BLACKBERRY  UNLOCK CODE AT&T USA BLACKBERRY TORCH 9800/ 9810/9860 picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.