mms.java
来自「A MMS sender written in Java」· Java 代码 · 共 98 行
JAVA
98 行
/***************************************************************************** Description: This class is used to send the actual MMS, an inputstream with the file to send is passed as a parameter. Created By: Oscar Vivall 2005-12-14 @file MMS.java COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2004. The software is the copyrighted work of Sony Ericsson Mobile Communications AB. The use of the software is subject to the terms of the end-user license agreement which accompanies or is included with the software. The software is provided "as is" and Sony Ericsson specifically disclaim any warranty or condition whatsoever regarding merchantability or fitness for a specific purpose, title or non-infringement. No warranty of any kind is made in relation to the condition, suitability, availability, accuracy, reliability, merchantability and/or non-infringement of the software provided herein. *****************************************************************************/import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import javax.microedition.io.*;import javax.wireless.messaging.*;import java.io.*;import java.util.*;public class MMS implements Runnable{ private Vector recipients = new Vector(); private byte[]data; public MMS(byte []b){ data = new byte[b.length]; System.arraycopy(b, 0, data, 0, b.length); System.out.println("Image Size:" + data.length); } public void addRecipient(String to){ recipients.addElement("mms://" + to); } public void send(){ if(!recipients.isEmpty()){ new Thread(this).start(); } } /* * The mms is sent in a separate thread. */ public void run() { MessageConnection msgConn = null; MultipartMessage mulMsg = null; String address = ""; address = (String)recipients.elementAt(0); try{ msgConn = (MessageConnection)Connector.open(address); mulMsg= (MultipartMessage)msgConn.newMessage(MessageConnection.MULTIPART_MESSAGE); for(int i=0; i<recipients.size(); i++){ System.out.println("Add>> " + (String)recipients.elementAt(i)); mulMsg.setAddress((String)recipients.elementAt(i)); }// mulMsg.setAddress("mms://+1555666444"); // add phone number.// mulMsg.setAddress("mms://name@mail.com"); // add mail address. mulMsg.setSubject("JAVA ME MMS TEST"); String time = String.valueOf(System.currentTimeMillis()); mulMsg.setHeader("X-Mms-Delivery-Time", time); mulMsg.setHeader("X-Mms-Priority", "high"); // -- Add text to the mms. String mimeType = "text/plain"; String encoding = "UTF-8"; String text = "Hello from my java app"; byte[] contents = text.getBytes(encoding); MessagePart msgPart = new MessagePart(contents, 0, contents.length, mimeType, "id1", "contentLocation", encoding); mulMsg.addMessagePart(msgPart); // -- Ad an image to the mms mimeType = "image/jpeg"; msgPart = new MessagePart(data, 0, data.length, mimeType, "id2", "bg.jpg", null); mulMsg.addMessagePart(msgPart); // send the mms msgConn.send(mulMsg); }catch(Exception e){ e.printStackTrace(); } System.out.println("DONE!"); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?