-
Interface Summary
Interface |
Description |
MMSDeliveryReport |
This interface represents a MMS Delivery Report.
|
MMSListener |
The MMSListener interface defines the methods required for processing
incoming multimedia-messages, MMS notifications and read- and delivery
reports.
|
MMSNotification |
This interface represents a notification about an incoming MMS waiting to be
picked up.
|
MMSReadReport |
This interface represents a MMS Read Report.
|
MMSReport |
Base interface for MMS read- and delivery reports.
|
MMSService |
The MMSService interface defines the methods for sending and receiving
Multimedia Messages (MMS).
|
-
Class Summary
Class |
Description |
MMSAddress |
This class represents an MMS address.
|
MMSCapability |
The MMSCapability class can be used to determine if a MMS Service has
a specific feature.
|
MMSDeliveryStatus |
This class is a representation of the X-MMS-Status attribute.
|
MMSServiceFactory |
Factory for constructing MMS Service objects.
|
MMSStatus |
This class represents a MMS Response status.
|
-
Exception Summary
Exception |
Description |
ConfigurationException |
This exception is used for signaling configuration problems.
|
MMSException |
Signals that an exception of some sort has occurred while processing MMS
messages and reports.
|
Package com.objectxp.mms Description
This package is the root package of the object XP Multimedia Message Service implementation.
The jSMS MMS implementation may be used to:
- submit Multimedia Messages from MMS User Agent (your GPRS-device) to MMS Relay/Server
- let the MMS Relay/Server push information about MMSMessage to the MMS User Agent as part of an MMSNotification.
- let the MMS User Agent pull MMSMessages from the MMS Relay/Server (fetch the MMSMessage)
The following example code demonstrates how to send a MMSMessage to the MMS-Proxy-Relay.
import java.io.File;
import java.io.IOException;
import java.net.URL;
import com.objectxp.mms.MMSAddress;
import com.objectxp.mms.MMSService;
import com.objectxp.mms.MMSServiceFactory;
import com.objectxp.mms.message.MMSMessage;
import com.objectxp.mms.message.SMILMessage;
/**
* This example demonstrates how to send a Multimedia Message (MMS)
*/
public class SendMMS
{
public static void main(String[] args)
{
MMSService mmsService = null;
// Construct a MMS Service using the MMS service factory
try {
MMSServiceFactory factory = MMSServiceFactory.createFactory(new File("/path/to/my/jsms.properties"));
mmsService = factory.getDefaultService();
} catch (Exception ex) {
System.err.println("Unable to create service. " + ex.getMessage());
System.exit(1);
}
// Create the MMS Message
MMSMessage msg = null;
try {
URL url = SendMMS.class.getResource("/path/to/my/smil.document");
msg = new SMILMessage(url);
msg.addTO(new MMSAddress(MMSAddress.TYPE_PLMN, "0987654321"));
} catch (IOException ex) {
System.err.println("Unable to create MMS Message. " + ex.getMessage());
System.exit(1);
}
// Send the Message
try {
mmsService.connect();
mmsService.send(msg);
mmsService.disconnect();
} catch (Exception ex) {
System.err.println("Unable to send MMS Message. " + ex.getMessage());
System.exit(0);
}
}
}
|
The next example shows you how to get a MMSMessage. A MMSMessage is not
sent to the client but only a MMSNotification is received using the common GSM Protocol.
The MMS service fetches the MMS using GPRS.
public class ReceiveExample implements MessageEventListener
{
private SmsService service;
private String configFile;
public static void main(String[] args) throws Exception
{
if(args.length < 1 ) {
System.err.println("Usage: ReceiveExample <config-file>");
System.exit(1);
}
ReceiveExample receiver = new ReceiveExample(args[0]);
// Start receiving MMS
receiver.startGsmService();
}
public ReceiveExample(String config) {
configFile=config;
}
/**
* Implementation of the MessageEventListener interface.
* Handle MessageEvents from the SMS service
*/
public void handleMessageEvent(MessageEvent event)
{
if( event.getType() != MessageEvent.MESSAGE_RECEIVED ) {
// We are only interested in incoming messages
return;
}
Message msg = event.getMessage();
if (msg != null && (msg instanceof MMSNotification))
{
MMSNotification notification = (MMSNotification)msg;
System.out.println("MMSNotification received, fetching MMS with ID:"+notification.getTransactionId());
// Disconnect the GSMService
if (service != null){
try {
service.stopReceiving();
service.disconnect();
} catch (MessageException e) {
System.err.println("disconnection SmsService failed.");
e.printStackTrace();
} finally {
service.destroy();
}
}
MMSService mmsService=null;
try {
// Create a service factory first
MMSServiceFactory factory = MMSServiceFactory.createFactory(new File(configFile));
// Get the default MMS Service
mmsService = factory.getDefaultService();
// Connect to the MMSC
mmsService.connect();
// Fetch the MMS
MMSMessage mms = mmsService.fetch(notification);
// Show incoming message
System.out.println("MMS Fetched:\n"+mms.toString());
} catch (Exception e) {
System.err.println("could not fetch MMSMessage with id "+notification.getTransactionId());
e.printStackTrace();
} finally {
// Disconnect from MMSC
if (mmsService!=null) {
try {
mmsService.disconnect();
} catch (Exception e) {
System.err.println("Could not disconnect mmsService after fetching."+e.getMessage());
e.printStackTrace();
}
}
}
// reconnect GSM service for further messages
try {
startGsmService();
} catch (Exception e) {
System.err.println("could not reconnect GsmSmsSerice.");
e.printStackTrace();
}
} else {
// incomming message is not a MMSNotification
System.out.println("received SMS but is not a MMSNotification -> ignore.");
}
}
private void startGsmService() throws IOException, MessageException
{
// Create and initialize a GSM SmsService
service = new GsmSmsService();
service.init(new File(configFile));
// Since MMS notifications come in multiple fragments, we engage the
// MultiPartReceiver for assembling them.
MultiPartReceiver mpr = new MultiPartReceiver(360*1000, 50, this);
service.addMessageEventListener(mpr);
service.connect();
service.startReceiving();
System.out.print("Press return to stop receiving messages");
System.in.read();
service.stopReceiving();
service.disconnect();
service.destroy();
}
}
|