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: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: OutboundSMSListener help

Check this thread.

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=15778&query.id=30...


Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 342
Registered: ‎02-04-2009
My Device: BB 8320

Re: OutboundSMSListener help

Refer for ESS setup:

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=29673#M29673 


Use Search. "Accept Solution" if the problem gets resolved.
Developer
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: OutboundSMSListener help

Thanks it worked for me.

 

Here I assign port number as "0" .MessageConnection _mc = (MessageConnection)Connector.open("sms://:0");

 

I want to know if there is another application on port 0 will my application listen to all SMS.

 

If not how can I assign a port number which can listen to all the SMS messages and which is not conflicting with any other application.

Developer
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: OutboundSMSListener help

I dont mind if the port is conflicting with any other application, I only want a universal port which can listen to all the SMS i.e Incoming and Outgoing SMS

 

 

 

Thanks....

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: OutboundSMSListener help

If you go thru previous posts of this thread you get some info. If you dn't use application should be able to intercept all incoming SMS, havn't tried for outgoing SMS. I guess it will work for outgoing SMS too.

Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: OutboundSMSListener help

I had read the previous thread, where he has mentioned only one MessageListener can use port 0.

 

But if there is some other application which is using MessageListener at port 0, How will my application come to know.

Developer
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: OutboundSMSListener help

 

Please throw some light regarding the port number which can listen to all incoming and outgoing SMS, regardless of an

 

application is using that port or not.

 

Please suggest me a way to assign a port for SMSListener which will have no conflict with other application.

 

 

 

Thanks.....

Developer
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: OutboundSMSListener help

Will port 0 work in all conditions.... If not please suggest some solution for that.

 

 

Thanks

BlackBerry Development Advisor
Posts: 15,694
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: OutboundSMSListener help

If port 0 is already in use by another application your application should receive an IOException stating that the port was already bound.  The only alternative is to open a DatagramConnection.

 

 What is - Different ways to listen for SMS messages
Article Number: DB-00579

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

 

You can listen for outbound SMS messages by using the net.rim.blackberry.api.sms.SendListener.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Highlighted
New Contributor
Posts: 9
Registered: ‎01-18-2011
My Device: Not Specified

Re: OutboundSMSListener help

Hi,    

           I tried this code. But this listener is not getting notified when a message is sent from device. I have pasted my code below

 

 

public class SMSListener implements OutboundMessageListener, MessageListener {
    private static final String CLASS_NAME = "SMSListener";
   
    private MessageConnection messConn;
   
    private boolean activated = false;
   
    private static SMSListener instance;
   
    public static SMSListener getInstance() {
        if(instance == null) {
            instance = new SMSListener();
        }
        return instance;
    }
    private SMSListener() {
       
    }
   
    public void activate() {
        if(activated) {
            return;
        }
        final String TAG = Utils.getLogTag(CLASS_NAME + ".activate()");
        try {
            messConn = (MessageConnection) Connector.open("sms://:0");
           
            messConn.setMessageListener(this);
            activated = true;
            Logger.getInstance().log(LogType.INFO, TAG + "SMS Listener got activated");
           
        } catch (Exception e) {
            Logger.getInstance().log(LogType.ERROR, Utils.getExceptionLog(TAG, e));
            return;
        }       
    }
   
    public void notifyIncomingMessage(MessageConnection conn) {
        final String TAG = Utils.getLogTag(CLASS_NAME + ".notifyIncomingMessage()");
        try {
            Message message = conn.receive();                       
           
            SMSMessage incomingMessage = new SMSMessage();
            incomingMessage.setPeerAddress(removeSMSPrefix(message.getAddress()));
            incomingMessage.setTimeStamp(message.getTimestamp());
            if(message instanceof MultipartMessage) {
                incomingMessage.setHasAttachment(true);
            }
            incomingMessage.setReceived(true);
           
            if(message instanceof TextMessage) {
                TextMessage textMessage = (TextMessage) message;
                incomingMessage.setMessage(textMessage.getPayloadText());
           
            } else  if (message instanceof BinaryMessage) {
                byte[] data = ((BinaryMessage) message).getPayloadData(); 
                incomingMessage.setMessage(new String(data, "UTF-8"));
           
            } else {
                Logger.getInstance().log(LogType.WARNING, TAG + "Incoming message from " + incomingMessage.getPeerAddress() + " is in invalid format");
                return;
            }
            Model.getInstance().addNewInboxSMSMessage(incomingMessage);
       
        } catch (Exception e) {
            Logger.getInstance().log(LogType.ERROR, Utils.getExceptionLog(TAG, e));
        }           
       
    }

    public void notifyOutgoingMessage(Message message) {
        final String TAG = Utils.getLogTag(CLASS_NAME + ".notifyOutgoingMessage()");
        try {
            Logger.getInstance().log(LogType.ERROR, TAG + "called");
            SMSMessage outgoingMessage = new SMSMessage();
            outgoingMessage.setPeerAddress(removeSMSPrefix(message.getAddress()));
            outgoingMessage.setTimeStamp(message.getTimestamp());
            outgoingMessage.setReceived(false);
           
            if(message instanceof TextMessage) {
                Logger.getInstance().log(LogType.INFO, TAG + "Detected text message");
                TextMessage textMessage = (TextMessage) message;
                outgoingMessage.setMessage(textMessage.getPayloadText());
           
            } else  if (message instanceof BinaryMessage) {
                Logger.getInstance().log(LogType.INFO, TAG + "Detected binary message");
                byte[] data = ((BinaryMessage) message).getPayloadData(); 
                outgoingMessage.setMessage(new String(data, "UTF-8"));
           
            } else {
                Logger.getInstance().log(LogType.WARNING, TAG + "Outgoing message to " + outgoingMessage.getPeerAddress() + " is in invalid format");
                return;
            }
            Model.getInstance().addNewOutboxSMSMessage(outgoingMessage);
       
        } catch (Exception e) {
            Logger.getInstance().log(LogType.ERROR, Utils.getExceptionLog(TAG, e));
        }
    }
   
    private String removeSMSPrefix(String address) {
        return StringUtilities.removeChars(address, "sms://");
    }
   
    public void deactivate() {
        if(!activated) {
            return;
        }
        final String TAG = Utils.getLogTag(CLASS_NAME + ".deactivate()");       
        try {
            messConn.setMessageListener(null);
            activated = false;
            Logger.getInstance().log(LogType.INFO, TAG + "Incoming Message Listener got deactivated");
        } catch (Exception e) {
            Logger.getInstance().log(LogType.ERROR, Utils.getExceptionLog(TAG, e));
        }
    }
   
    public boolean isActive() {
        return activated;
    }
   
}