Help Center
Local Navigation
BlackBerry Manuals & Help
>
Developer Documentation
>
Java Development Guides and API Reference
>
Development Guide
Network Communication - BlackBerry Java SDK - 6.0
Send data using a FireAndForgetDestination object
-
Import the required classes and interfaces.
import net.rim.device.api.io.messaging.*; import net.rim.device.api.io.URI;
-
Create a
URI object to pass to the
DestinationFactory class.
URI uri = new URI("http://www.example.com"); -
Create a
FireAndForgetDestination object.
FireAndForgetDestination ffd = null;
-
Retrieve the
FireAndForgetDestination object for your context, if
one exists.
try { ffd = (FireAndForgetDestination) DestinationFactory.getSenderDestination ("MyContext", uri); -
If no
FireAndForgetDestination exists, create one.
if(ffd == null) { ffd = DestinationFactory.createFireAndForgetDestination (new Context("MyContext"), uri); } -
Create a
ByteMessage object and populate it with information
to send to a web service.
ByteMessage myMsg = ffd.createByteMessage(); myMsg.setStringPayload("I love my BlackBerry device!"); -
Cast your message as an
HTTPMessage to set the HTTP method that you want to
use.
((HttpMessage) myMsg).setMethod(HttpMessage.POST);
-
Send the message to the web service.
ffd.sendNoResponse(myMsg);
-
Catch any errors that occur if the message could not be sent for
some reason.
catch (Exception e) { // Process the error }
Next topic: Parsing a common Internet data format
Previous topic: Implement the MessageListener interface