📄 sendexample.java~1~
字号:
package mms;import java.io.File;import java.io.FileInputStream;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;import com.objectxp.mms.message.smil.Body;import com.objectxp.mms.message.smil.Head;import com.objectxp.mms.message.smil.Image;import com.objectxp.mms.message.smil.SmilDocument;import com.objectxp.mms.message.smil.Text;import com.objectxp.mms.message.smil.Timer;/** * This example demonstrates how how to send a MultiMediaMessage (MMS) * * There are serveral ways to create a MMSMessage: * <ul> * <li> * instantiate a MMSMessage and add some GenericMessageParts. This kind of MMS does not * provide a smil-document. The target device will decide in which order to display the parts. * (not shown in this example) * </li> * <li> * create a SMILMessage with a URL. The MMSMessage will load the predefined smil document * and its related parts from the given URL. (use the [LOAD_NEWS] property or any URL) * </li> * <li> * create a SmilDocument using the com.objectxp.mms.message.smil classes. (use no <smilDocument> property) * </li> * </ul> * * */public class SendExample { public static void main(String[] args) throws Exception { if (args.length<2 || args.length>3) { System.out.println("Usage: SendExample <phoneNumber> <smilDocument> <propertyFile> \n\n" + "<phoneNubmer> is the phoneNumer of the destination of the MMS.\n" + "<smilDocument> is the location of your smil document. \n" + " Set a path to your own SMIL document or use:\n"+ " - BUILD builds a SMIL document with the smil-classes \n" + " - LOAD_NEWS for the examples/mms/media/news/news.smil \n" + " - LOAD_SPORT for the examples/mms/media/sport/sport.smil \n" + " - LOAD_BUSINESS for the examples/mms/media/business/business.smil \n" + "<propertyFile> is the reference to the configuration file. Per default,\n" +
" the bin/jsms.conf file is taken.\n\n"); return; } String location = null; String phone = args[0]; String file = "bin/jsms.conf"; // select SMIL document location = args[1]; if (location.equals("LOAD_NEWS")) { location = "mms/media/news/news.smil"; } else if (location.equals("LOAD_SPORT")) { location = "mms/media/sport/sport.smil"; } else if (location.equals("LOAD_BUSINESS")) { location = "mms/media/business/business.smil"; } // configuration file if (args.length >=3){ file = args[2]; } // initialize Service MMSServiceFactory factory = MMSServiceFactory.createFactory(new File(file)); MMSService mmsService = factory.getDefaultService(); MMSMessage msg; if (!"BUILD".endsWith(location)){ // load smilDocument from the given URL URL url = new SendExample().getClass().getClassLoader().getResource(location); msg = new SMILMessage(url); } else { // create smil-document using the com.objectxp.mms.message.smil classes Body body = new Body(); // add first frame Timer part1 = new Timer(); part1.addAttribute("dur","3s"); body.addElement(part1); part1.addElement(new Text("Achtung ein Elch kommt.")); // add second frame Timer part2 = new Timer(); part2.addAttribute("dur","3s"); body.addElement(part2); part2.addElement(new Image(new FileInputStream("mms/media/sample/warn.jpg"), "warn.jpg", "image/jpeg")); SmilDocument doc = new SmilDocument(); doc.addElement(new Head()); doc.addElement(body); // create mmsMessage msg = new SMILMessage(doc); } MMSAddress toAddr = new MMSAddress(MMSAddress.TYPE_PLMN, phone); msg.addTO(toAddr); // send Message try { String sName = mmsService.getName(); System.out.print("Establishing connection to MMSC (service: "+(sName==null?"DEFAULT":sName)+")..."); mmsService.connect(); System.out.println("OK"); System.out.print("Sending MMS to "+toAddr+"..."); mmsService.send(msg); System.out.println("OK"); }catch (Exception e){ System.err.println("could not send Message: "+ e); e.printStackTrace(); } finally{ System.out.print("Disconnecting...."); mmsService.disconnect(); System.out.println("OK"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -