使用Java发送短信(GSM Dongle)

时间:2013-02-28 18:12:30

标签: java api sms

我正在尝试开发一个应用程序,让我使用连接在USB端口上的GSM Dongle发送短信。我已经下载了javaxcomm api并将文件放在适当的文件夹中。自从我的O.S.是Windows 7(64位),我已经下载了jdk的32位版本。但是,我仍然无法继续前进。目前我遇到了NoSuchPortException。

此行周围出现错误:

portId = CommPortIdentifier.getPortIdentifier(parameters.getPortName());

这是完整的代码。

public class SMSClient implements Runnable{

  public final static int SYNCHRONOUS=0;
  public final static int ASYNCHRONOUS=1;
  private Thread myThread=null;

  private int mode=-1;
  private String recipient=null;
  private String message=null;

  public int status=-1;
  public long messageNo=-1;


  public SMSClient(int mode) {
      this.mode=mode;
    }

  public int sendMessage (String recipient, String message){
    this.recipient=recipient;
    this.message=message;
    //System.out.println("recipient: " + recipient + " message: " + message);
    myThread = new Thread(this);
    myThread.start();
//    run();
    return status;
    }
    public void run(){

    Sender aSender = new Sender(recipient,message);

    try{
      //send message
          aSender.send ();

         // System.out.println("sending ... ");

      //in SYNCHRONOUS mode wait for return : 0 for OK,
      //-2 for timeout, -1 for other errors
      if (mode==SYNCHRONOUS) {
          while (aSender.status == -1){
            myThread.sleep (1000);
          }
      }
      if (aSender.status == 0) messageNo=aSender.messageNo ;

    }catch (Exception e){

        e.printStackTrace();

    }

    this.status=aSender.status ;

    aSender=null;


  }
}

0 个答案:

没有答案