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
Highlighted
Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone
Accepted Solution

How can we implement OutboundMessageListener in blackberry?

Hi all,

 

Not getting any way to implement OutboundMessageListener in blackberry... please help me out

 

 

Thanks and Regards

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How can we implement OutboundMessageListener in blackberry?

Can you show use the code you are currently using and what you have tried to do?

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: How can we implement OutboundMessageListener in blackberry?

public class MainClass extends UiApplication implements OutboundMessageListener, MessageListener

{

private String url = "file:///store/home/user/MainClass.txt";

public static void main(String[] args)

{

MainClass mainClass = new MainClass();

mainClass.enterEventDispatcher();

}

public MainClass()

{

try

{

MessageConnection _mc = (MessageConnection)Connector.open("sms://");

_mc.setMessageListener(this);

logFile.log(url, "Listener Added");

}

catch (IOException e)

{

logFile.log(url, "IOException ----> " + e.toString());

}

UiApplication.getUiApplication().pushScreen(new SmsCountScreen());

}

  /* * (non-Javadoc) * @seejavax.wireless.messaging.MessageListener#notifyIncomingMessage(javax.wireless.messaging.MessageConnection) */

public void notifyIncomingMessage(MessageConnection conn)

{

logFile.log(url, "Incoming Message!");

UiApplication.getUiApplication().invokeAndWait(new Runnable()

{

public void run()

{

Dialog dialog = new Dialog(Dialog.D_OK, "Message Received!", 0, null, Dialog.FIELD_HCENTER); Ui.getUiEngine().pushGlobalScreen(dialog, 1, UiEngine.GLOBAL_MODAL);

}

});

}

/* * (non-Javadoc)

*@seenet.rim.blackberry.api.sms.OutboundMessageListener#notifyOutgoingMessage(javax.wireless.messaging.Message) */

public void notifyOutgoingMessage(Message message)

{

logFile.log(url, "Outgoing Message!");

UiApplication.getUiApplication().invokeAndWait(new Runnable()

{

public void run()

{

Dialog dialog = new Dialog(Dialog.D_OK, "Message Sent!", 0, null, Dialog.FIELD_HCENTER); Ui.getUiEngine().pushGlobalScreen(dialog, 1, UiEngine.GLOBAL_MODAL);

}

});

}

}

 using this code and getting error  IOException: operation not permitted on a client connection

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How can we implement OutboundMessageListener in blackberry?

Sorry this is not an area of expertise, but I wonder if reading the API actually helps.  The error you see is exactly what the API says it will do:

 

"IOException - if the connection has been closed, or if an attempt is made to register a listener on a client connection."

 

The API also describes what the difference is between a client and a Server connection:

 

"In a client mode connection, messages can only be sent. A client mode connection is created by passing a string identifying a destination address to the Connector.open() method. This method returns a MessageConnection object.

 

In a server mode connection, messages can be sent or received. A server mode connection is created by passing a string that identifies an end point (protocol dependent identifier, for example, a port number) on the local host to the Connector.open() method. If the requested end point identifier is already reserved, either by some system application or by another Java application, Connector.open() throws an IOException. Java applications can open MessageConnection connections for any unreserved end point identifier, although security permissions might not allow it to send or receive messages using that end point identifier."

 

Does this help?

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: How can we implement OutboundMessageListener in blackberry?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How can we implement OutboundMessageListener in blackberry?

The difference is this:

 

mc =(MessageConnection)Connector.open("sms://:0");

As the API documentation I pasted above suggests

"A server mode connection is created by passing a string that identifies an end point (protocol dependent identifier, for example, a port number)"

 

By adding the port you turned into a Server mode connection. 

 

The listener you are adding is a listener for incoming messages that you have extended to add outgoing messages.  So the connector must be capable of receiving incoming messages.  

 

A server mode connection is capable of accepting and sending messages, client mode can only send.