Purpose: Today most mobile phones are enabled to use the Multimedia Messaging Service (MMS), a important extension of SMS. With MMS mere kind of multimedia information may be exchanged, so text documents, audio, images and even video. An typical MMS message contains several message parts. Data in each part is transferred as byte stream with its own mime type. The WMA (Wireless Mobile API) contains all necessary classes to handle MMS, but the Gidlet framework puts another layer of simplicity on top of it. In this example, an image stored in a resource file is sent to a given recipient. MMS uses a string type application identifier, that must correspond to the receiver MIDlet's identifier. If no identifier is used, the default MMS application of the mobile phone (and not a MIDlet) will capture the message.
Execute MmsSendGidlet (if you have the Sun's Wireless Toolkit (WTK) installed and the JAD extension registered. Learn how to register the JAD extension). Execute MmsReceiveGidlet at the same time to communicate. Discussion: The most important parameter of sendMMS() is an array of MessageParts. Each part contains a byte array for the data, a mime type, a string identifier, a location and an encoding scheme. We use the following constructor, as specified in the WMA documentation: MessagePart(byte[] contents, String mimeType,String contentId, String contentLocation, String encoding) When we send image to the standard application, only the data and the mime type are used. If the receiver is a MIDlet, the contentId is important in order to identify the part. sendMMS() spawns a thread for sending the MMS and returns immediately. This is a good idea, because on a real device the process may take some time and the program should not freeze. When the job is done, a callback notification is invoked and the parameter status informs us also about success or failure. Instead of using the WTK emulator, that is somewhat boring, you may send the picture from a real device to a (eventually the same) real device. If you are afraid of the costs, you may write a receiver MIDlet as follows. Do not forget to change the appId to "MmsGidlet" in the MmsSendGidlet. Run the emulator twice at the same time for the sending and receiving device and select the phone number as shown on top of the emulated phone. (Sometimes the WTK does not like the two program instances and may even crash. Rerun it and hopefully it works.)
Execute MmsReceiveGidlet (if you have the Sun's Wireless Toolkit (WTK) installed and the JAD extension registered. Learn how to register the JAD extension). Execute MmsSendGidlet at the same time to communicate.
Twelfth example Purpose: With MMS you can even send an e-mail without having direct access to the internet. The Gidlet framework wraps the sendMMS() in a very simple and common sendMMSMail() method that takes the recipients mail address, the mail subject and the mail message as parameters (the coding scheme is ISO-8859-1).
Execute MmsMailGidlet (if you have the Sun's Wireless Toolkit (WTK) installed and the JAD extension registered. Learn how to register the JAD extension) Discussion: sendMMSMail() returns immediately and an internal thread will do the job. When the thread terminates, it notifies us by calling notifyOutgoingMMS().
Thirteenth example Purpose: Why not send a sound message with MMS? It's easy. put text and audio (from a resource file) in a MessagePart, add a subject and call sendMMS(). Keep in mind that the size of a MMS must be rather small (depending on your phone company, but normally smaller than 100 kBytes). // MmsAudioGidlet.java Execute MmsAudioGidlet (if you have the Sun's Wireless Toolkit (WTK) installed and the JAD extension registered. Learn how to register the JAD extension) | |||||||||||