java left logo
java middle logo
java right logo
 

Home arrow Java ME Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4088
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
Sending and Recieving MMS on J2ME devices E-mail
User Rating: / 61
PoorBest 

Wireless Messaging API (JSR-120 or WMA) for Java, allows access to wireless communication resources on J2ME devices. MMS is a mulitpart message and WMA api support mulitpart messages.

Below is the illustration of sending and recieving MMS on mobile phones.

public void sendMMS() 
{
  String appID = getAppProperty("MMS-ApplicationID");
  String address = "mms://+5550000:" + appID;

  MessageConnection mmsconn = null;

  try 
  {
    /** Open the message connection. */
    mmsconn = (MessageConnectionConnector.open(address);

    MultipartMessage mmmessage =(MultipartMessagemmsconn.newMessage(
      MessageConnection.MULTIPART_MESSAGE);
    mmmessage.setAddress(address);

    MessagePart[] parts = getParts();

    for (int i = 0; i < parts.length; i++
    {
      mmmessage.addMessagePart(parts[i]);
    }

    mmmessage.setSubject("MMS Text");
    mmsconn.send(mmmessage);
  
  catch (Exception e) {
  }

  if (mmsconn != null
  {
    try 
    {
      mmsconn.close();
    
    catch (IOException ioe) {
    }
  }
}

public MessagePart[] getParts() 
{
  // parts is a Vector that contains Mulitpart messages
  MessagePart[] partsArray = new MessagePart[parts.size()];
  parts.copyInto(partsArray);
  return partsArray;
}

public void addPart()
{  
  Vector parts = new Vector();
  int counter = 0;
  MessagePart mpart;
  
  /*This is to add Text*/
  String mimeType = "text/plain";
  String encoding = "UTF-8";
  String text = "Hello";
  byte[] contents = text.getBytes(encoding);
  mpart = new MessagePart(contents, 0, contents.length, mimeType, "id" +
    counter, "contentLocation", encoding);

  counter ++;

  /*This is to add Image*/
  String mimeType = "image/png";
  String image = "/hello.png";
  InputStream is = getClass().getResourceAsStream(image);
  byte[] contents = new byte[is.available()];
  is.read(contents);
  mpart = new MessagePart(contents, 0, contents.length,mimeType, "id" 
    counter,"contentLocation"null);
  parts.addElement(mpart);
  counter ++;
}

public void run() 
{
  String mmsConnection = "mms://:" + appID;
  try 
  {
    mmsconn = (MessageConnectionConnector.open(mmsConnection);
    mmsconn.setMessageListener(this);
  
  catch (IOException ioe) {
  }
  try 
  {
    Message msg = mmsconn.receive();
    if (msg != null
    {
      String senderAddress = msg.getAddress();
      String title = senderAddress.substring(6);
      if (msg instanceof MultipartMessage
      {
        MultipartMessage mpm = (MultipartMessage)msg;
        String subject = mpm.getSubject();
        String date = mpm.getTimestamp().toString();
        MessagePart[] parts = mpm.getMessageParts();
        if (parts != null
        {
          for (int i = 0; i < parts.length; i++
          {
            MessagePart mp = parts[i];
            String mimeType = mp.getMIMEType();
            String contentLocation = mp.getContentLocation();
            byte[] ba = mp.getContent();
            try 
            {
              Image image = Image.createImage(ba, 0, ba.length);
            }
            catch (IllegalArgumentException iae
            {}
          }
        }
      }
    }
  
  catch (IOException e) {
  }
}


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.