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

📄 sendseomessage.java

📁 控制手机发送短信程序
💻 JAVA
字号:
package sms;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import com.objectxp.msg.GsmSmsService;
import com.objectxp.msg.MessageException;
import com.objectxp.msg.SEOMessage;
import com.objectxp.msg.SmsService;
import com.objectxp.msg.smart.VCard;

/**
 * This example demonstrates how to send a various objects to a Siemens Mobile
 * phone using the "Siemens Exchange Object (SEO)" format.
 *
 */
public class SendSEOMessage
{
  public static void main(String[] args) throws IOException, MessageException
  {
    if(args.length < 3 ) {
      System.err.println("Usage: SendSEOMessage <config-file> <recipient> <type> ...");
      System.exit(1);
    }

    String configFile = args[0];
    String sender = "OXP";
    String recipient = args[1];
    String type = args[2];
    String objectType = null;
    String objectName = null;

    SEOMessage msg = null;
    InputStream in = null;

    if( "midi".equals(type) ) {
      objectType = SEOMessage.TYPE_MIDI;
      objectName = "seo.mid";
      in = SendSEOMessage.class.getResourceAsStream("/media/seo.mid");
    } else if ( "bmp".equals(type) ) {
      objectType = SEOMessage.TYPE_BMP;
      objectName = "seo.bmp";
      in = SendSEOMessage.class.getResourceAsStream("/media/seo.bmp");
    } else if ( "data".equals(type) ) {
      // We need two additional arguments - contentType and filename holding data
      if( args.length < 5 ) {
        System.err.println("Type \"data\" requires two additional arguments: <content-type> and <file>");
        System.exit(1);
      }
      objectType = args[3];
      File input = new File(args[4]);
      in = new FileInputStream(input);
      objectName = input.getName();

    } else if ( "vcard".equals(type) ) {
      objectType = SEOMessage.TYPE_VCARD;
      objectName = "VCard.vcf";

      // Use the VCard class to create a VCARD
      VCard vc = new VCard();
      vc.setItem(VCard.NAME, "John Doe");
      vc.setItem(VCard.TITLE,"CTO");
      vc.setItem(VCard.TEL,"+4123456789");
      msg = new SEOMessage(vc);
    } else {
      System.err.println(type+": Unknown value for \"type\"");
      System.exit(1);
    }

    if( msg == null ) {
      msg = new SEOMessage();
      if( in == null ) {
        System.err.println("InputStream is null.");
        System.exit(1);
      }
      msg.setUserData(in);
    }
    msg.setSender(sender);
    msg.setRecipient(recipient);
    msg.setObjectType(objectType);
    msg.setObjectName(objectName);

    // Create and initialize the SmsService (Replace GsmSmsService with
    // the SmsService Implementation of your choice).
    SmsService service = new GsmSmsService();
    service.init(new File(configFile));
    service.connect();
    try {
      service.sendMessage(msg);
    } finally {
      service.disconnect();
    }
  }
}

⌨️ 快捷键说明

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