BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 04-30-2008, 11:14 PM   #1
skynetchris
Knows Where the Search Button Is
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: optus
Posts: 24
Default SMS recieving/capture.

Please Login to Remove!

Hi everyone.

I'm writing an application that will (hopefully =) read sms sent to a blackberry 8310 handset. Specifically I am reffering to blackberry system messages. For now, I'd be happy to recieve/read any messages. I have tried two approaches with neither seeming to work (no message displayed). I used the blackberry knowledge base article as reference and developers guide Receive an SMS message:


Communicator being the parent class the instantiated the thread.

updateLocationScreen simply does an EditField.insert(msg);


Code:
    
        //EXECUTED IN CONSTRUCTOR
        ListeningThread listen = new ListeningThread(this);
        listen.start();
        //END EXECUTED IN CONSTRUCTOR

        private static class ListeningThread extends Thread { 
        Communicator com;
        private boolean _stop = false;
        private MessageConnection _mc;
        public synchronized void stop() {
            _stop = true;
            try {
                _mc.close(); // Close the connection so the thread returns.
            } catch (IOException e) {
                System.err.println(e.toString());
            }
        }
        ListeningThread(Communicator comPass){
            com = comPass;
        }
         
        public void run() { 
        try {
            com.updateLocationScreen("\n\nListening for messages...\n");
            _mc = (MessageConnection)Connector.open("sms://");
            for(;;) {
                if ( _stop ) {
                    return;
                }
                Message m = _mc.receive();
                String address = m.getAddress();
                String msg = null;
                if ( m instanceof TextMessage ) {
                    TextMessage tm = (TextMessage) m;
                    msg = tm.getPayloadText();
                }
                com.updateLocationScreen("Message received: " + msg);
                com.updateLocationScreen("From: " + address);
                //System.exit(0);
            }
        }
        catch (IOException e) {
            System.err.println(e.toString()); 
        } 
        } 
    }
AND (the version I'd most prefer to work as its independant of type of message)

Code:
    
      //EXECUTED IN CONSTRUCTOR
      ListeningThread listen = new ListeningThread(this);
      listen.start();
     //END EXECUTED IN CONSTRUCTOR

    //New SMS handling class
    private static class ListeningThread extends Thread { 
        private boolean _stop = false; 
        private DatagramConnection _dc;
        Communicator com;
        ListeningThread(Communicator comPass){
            com = comPass;
        } 
        public synchronized void stop() { 
               _stop = true; 
               try { 
                       _dc.close(); // Close the connection so the thread returns. 
               } catch (IOException e) {
                       //System.err.println(e.toString()); 
               } 
        } 
    public void run() { 
       try {
            com.updateLocationScreen("\n\nListening for messages...\n"); 
            _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()); 
                      com.updateLocationScreen("Message received: " + msg);
                      com.updateLocationScreen("From: " + address); 
                      //System.exit(0); 
               } 
          } catch (IOException e) {
                   //System.err.println(e.toString()); 
          } 
    } 
    }
Screen output never displays any recieved message data, it does display 'Listening for messages', as expected.

Any ideas?
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


5L Electric Sheep Goat Milking Machine 110v Bucket Vacuum Impulse Pump Milker picture

5L Electric Sheep Goat Milking Machine 110v Bucket Vacuum Impulse Pump Milker

$108.73



Appion MGAVCT 1/4 Inches MegaFlow Vacuum-Rated Valve Core Removal Tool picture

Appion MGAVCT 1/4 Inches MegaFlow Vacuum-Rated Valve Core Removal Tool

$65.08



80813 Shop Vacuum Kit, 2.5

80813 Shop Vacuum Kit, 2.5", Blue/Orange

$58.65



4.5 CFM Single-Stage Rotary Vacuum Pump HVAC/Auto AC 4.5CFM 1/3HP 1/4

4.5 CFM Single-Stage Rotary Vacuum Pump HVAC/Auto AC 4.5CFM 1/3HP 1/4"ACME inlet

$29.34



Commercial Vacuum Packing Sealing Machine Setchen Digital Food Chamber Sealer US picture

Commercial Vacuum Packing Sealing Machine Setchen Digital Food Chamber Sealer US

$324.90



FEBCO 765DBV 3/4in Bronze FNPT Pressure Vacuum Breaker NEW picture

FEBCO 765DBV 3/4in Bronze FNPT Pressure Vacuum Breaker NEW

$89.99







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