HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Building a J2ME Multimedia Messaging Service Client"
Vol. 9, Issue 5, p. 24

	



Listing 1

int i = dis.readUnsignedByte();

if(i >= 0 && i <= 31) {
  tokenObject = new Integer(i);
  tokenType = Token.SHORT_LENGTH;
  tokenStateQueue = 
    dataTokenizer.getTokenStateQueue(tokenState, 
  dis.peekByte(1));
} else if(i == 31) {
   tokenObject = readUintvarInteger(dis);
   tokenType = Token.UINTVAR_INTEGER;
} else if(i == 34) {
   tokenObject = readString(dis);
   tokenType = Token.QUOTED_STRING;
} else if(i == 127) {
   tokenObject = readString(dis);
   tokenType = Token.TEXT_STRING;
} else if(i >= 32 && i <= 127) {
   tokenObject = readExtendedMedia(dis, i);
   tokenType = Token.EXTENSION_MEDIA;
} else if(i >= 128 && i <= 255)
   tokenObject = new Integer((i & 0x7f));
   tokenType = Token.SHORT_INTEGER;
   tokenState = i;
} ...
Token t = new Token(tokenType, (Object) tokenObject);


Listing 2

if(urlConnection.startsWith("http:")) {
  httpConnection = (HttpConnection) Connector.open(urlConnection);
  is = httpConnection.openInputStream();            
} else if(urlConnection.startsWith("sms:")) {
  BinaryMessage bm = null;
  conn = (javax.wireless.messaging.MessageConnection)
  Connector.open("sms://:1234");
  bm = (BinaryMessage) conn.receive();
  byte[] data = bm.getPayloadData();
  is = (InputStream) new ByteArrayInputStream(data);                     
} else {
  throw new IOException("Unrecognized Message Type");
}
  PeekInputStream pis = new PeekInputStream(is);        
  MultimediaMessage mm = new MultimediaMessage();
  MultimediaParser mp = new MultimediaParser();
  mp.parse(pis, mm);


Listing 3

MessageConnection conn=(MessageConnection)  
  Connector.open("sms://:1234");
mediaMessage = (MultimediaMessage) conn.receive();
String header = mediaMessage.getHeader("X_MMS_MESSAGE_TYPE")
int messageType= MessageType.lookupMessageType(header);
String contentUrl = mediaMessage.getHeader("X_MMS_CONTENT_LOCATION");

if(messageType == MessageType.M_NOTIFICATION) {
   conn = (MessageConnection) Connector.open(contentUrl);
   mediaMessage = (MultimediaMessage) conn.receive();
}

MultimediaViewer viewer = new MultimediaViewer(this, mediaMessage);
viewer.displayView();

 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.