⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendemsmessage.java~1~

📁 控制手机发送短信程序
💻 JAVA~1~
字号:
import java.awt.Image;import java.awt.Toolkit;import java.io.File;import java.io.IOException;import java.net.URL;import com.objectxp.msg.GsmSmsService;import com.objectxp.msg.MessageException;import com.objectxp.msg.SmsService;import com.objectxp.msg.ems.EMSAnimation;import com.objectxp.msg.ems.EMSElement;import com.objectxp.msg.ems.EMSMessage;import com.objectxp.msg.ems.EMSPicture;import com.objectxp.msg.ems.EMSSound;import com.objectxp.msg.ems.EMSText;import com.objectxp.msg.ems.EMSTextFormat;/** * This example demonstrates how to send a EMSMessage using jSMS. * The EMSMessage consists out of: * <ul> * <li>a text message</li> * <li>a formated text (<b><i>bold italic</i></b>) </li> * <li>a 16x16 pixel picture</li> * <li>a userdefined animation with 4 frames</li> * <li>a predefined animation with 6 frames</li> * <li>a userdefined melody (iMelody)</li> * <li>a predefined sound</li> * </ul> *   * */public class SendEMSMessage {  public static void main(String args[]) throws IOException, MessageException  {    if(args.length != 2 ) {      System.err.println("Usage: SendEMSMessage <config-file> <recipient>");      System.exit(1);    }    // Create and initialize the SmsService (Replace GsmSmsService with    // the SmsService Implementation of your choice).    SmsService service = new GsmSmsService();    service.init(new File(args[0]));        // create picture message    EMSMessage ems = new EMSMessage();    // add elements to the message    ems.add(getEMSText());    ems.add(getEMSFormatedText());    ems.add(getEMSPicture());    ems.add(getEMSAnimation());    ems.add(getEMSPredefAnimation());    ems.add(getEMSSound());    ems.add(getEMSPredefSound());    // set recipient    ems.setRecipient(args[1]);    // connect, send message and disconnect     try {      service.connect();      System.out.println("connected...");      service.sendMessage(ems);      System.out.println("mesage sent...");      service.disconnect();      System.out.println("disconnected...");    }    finally {      service.destroy();     }  }      /* *************************************************/  /*                                                 */  /*       helper methods to create EMSElements      */  /*                                                 */  /* *************************************************/  /**   * @see EMSText   * @return EMSElement   */  private static EMSElement getEMSText() {    return new EMSText("This is a unformated text.");  }    /**   * @see EMSText   * @see EMSTextFormat   * @return EMSElement   */  private static EMSElement getEMSFormatedText() {    EMSTextFormat format = new EMSTextFormat();    format.setSize(EMSTextFormat.SIZE_LARGE);    format.setBold(true);    return new EMSText("Large bold text", format);  }    /**   * @see EMSPicture   * @return EMSElement   */  private static EMSElement getEMSPicture(){    URL url = SendEMSMessage.class.getResource("/media/small.gif");    Image image = Toolkit.getDefaultToolkit().getImage(url);    EMSPicture pic = new EMSPicture(image);    return pic;      }    /**   * @see EMSAnimation   * @return EMSElement   */  private static EMSElement getEMSAnimation() {    // big pictures 16x16    EMSPicture aniPic1 = new EMSPicture(Toolkit.getDefaultToolkit().getImage(SendEMSMessage.class.getResource("/media/big_ani1.gif")));    EMSPicture aniPic2 = new EMSPicture(Toolkit.getDefaultToolkit().getImage(SendEMSMessage.class.getResource("/media/big_ani2.gif")));    EMSPicture aniPic3 = new EMSPicture(Toolkit.getDefaultToolkit().getImage(SendEMSMessage.class.getResource("/media/big_ani3.gif")));    EMSPicture aniPic4 = new EMSPicture(Toolkit.getDefaultToolkit().getImage(SendEMSMessage.class.getResource("/media/big_ani4.gif")));    EMSPicture[] animation = {aniPic1, aniPic2, aniPic3, aniPic4};    return new EMSAnimation(animation);  }    /**   * @see EMSAnimation   * @return EMSElement   */  private static EMSElement getEMSPredefAnimation() {    return EMSAnimation.LAUGHING;  }    /**   * @see EMSSound   * @return EMSElement   */  private static EMSElement getEMSSound() {    String iMelody =  "BEGIN:IMELODY\n"+                      "BEAT:160\n"+                      "MELODY:*4c1*4d3.*4#d2.*4c2.*4b4*5c4*4b4*5c4*4b4*5c4*4b4*5c4*4b4*5c4*4b4*5c4*4b4*5c1\n"+                      "END:IMELODY";    return new EMSSound(iMelody);  }  /**   * @see EMSSound   * @return EMSElement   */  private static EMSElement getEMSPredefSound() {    return EMSSound.DRUM;  }  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -