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

Java Development

Reply
Developer
Posts: 110
Registered: ‎10-22-2009
My Device: 9700
My Carrier: ChinaMobile
Accepted Solution

messagelistener problem

 MessageConnection messconn;
 messconn = (MessageConnection) Connector.open("sms://:0");
 MessageListener ml = new MessageListener(){
public void notifyIncomingMessage(MessageConnection conn) {
  System.out.println("=========================detect a coming sms!");

 Sometime I can catch the incoming sms via above code and sometime not.

Any guys know the reason?

Best Regards,
Tiandi
www.tiandiyoyo.com
Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: messagelistener problem

hi tiandi79,

 

I've read somewhere here that sometimes there is a conflict with the other message listener that's there is a possibility that you cannot capture some of the incoming sms message. I'll try to look for it. 

 

You can use DatagramConnection instead.Smiley Happy

 

check this out:

 

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

 

Developer
Posts: 110
Registered: ‎10-22-2009
My Device: 9700
My Carrier: ChinaMobile

Re: messagelistener problem

hi Johnbibs.

 

Thank you for ur quickly response.

 

Yes,I think u right. I have no way to find out the reason in fact.

 

Also I have seen URL which u gave but I am not sure is there a listener for DatagramConnection?

 

If not ,how to hold it by background?

Best Regards,
Tiandi
www.tiandiyoyo.com
Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: messagelistener problem

 

        // LISTEN FOR INCOMING MESSAGES
        Datagram d = null;
        try {
            d = dc.newDatagram(dc.getMaximumLength());
            dc.receive(d);
            byte[] bytes = new byte[d.getLength()];
            bytes = d.getData();
            String msg = new String(bytes);
            String address = d.getAddress();
            int smsSize = d.getLength();

            if (msg != null || msg.trim().equalsIgnoreCase("")) {
                System.out.prinln(msg);
            }

        } catch (IOException ioe) {
          System.out.println();
        } catch (Exception ex) {
          System.out.println();
        }

 You can create a background application which is configured to start on startup. And you can put this on a thread. Smiley Happy 

 

Developer
Posts: 110
Registered: ‎10-22-2009
My Device: 9700
My Carrier: ChinaMobile

Re: messagelistener problem

o,tat like a individual thread as below.

 while (true)

{

detect sms;

}

it will run all the time. Does it use more power consumptive and CPU?

 

Best Regards,
Tiandi
www.tiandiyoyo.com
Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: messagelistener problem

I have that implementation on one of my application and didn't observed any noticeable change on the device response time nor battery consumption. Smiley Happy So i guess that's fine Just a note that if ever you will process the message upon receiving, I suggest that you put that processing on the separate thread Smiley Happy 

 

 

Developer
Posts: 110
Registered: ‎10-22-2009
My Device: 9700
My Carrier: ChinaMobile

Re: messagelistener problem

Thank you very much!

Best Regards,
Tiandi
www.tiandiyoyo.com