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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


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