Exemple #1
0
  public static void main(String[] args) {
    CService srv = new CService("COM1", 57600, "Nokia", "");

    System.out.println();
    System.out.println("ReadMessages: Synchronous Reading.");
    System.out.println("  Using " + CService._name + " " + CService._version);
    System.out.println();

    try {
      srv.setSimPin("0000");

      // OK, let connect and see what happens... Exceptions may be thrown
      // here!
      srv.connect();

      // Lets get info about the GSM device...
      System.out.println("Mobile Device Information: ");
      System.out.println("	Manufacturer  : " + srv.getDeviceInfo().getManufacturer());
      System.out.println("	Model         : " + srv.getDeviceInfo().getModel());
      System.out.println("	Serial No     : " + srv.getDeviceInfo().getSerialNo());
      System.out.println("	IMSI          : " + srv.getDeviceInfo().getImsi());
      System.out.println("	S/W Version   : " + srv.getDeviceInfo().getSwVersion());
      System.out.println("	Battery Level : " + srv.getDeviceInfo().getBatteryLevel() + "%");
      System.out.println("	Signal Level  : " + srv.getDeviceInfo().getSignalLevel() + "%");
      System.out.println(
          "	GPRS Status   : " + (srv.getDeviceInfo().getGprsStatus() ? "Enabled" : "Disabled"));
      System.out.println("");

      // Write your test calls here.
      // ...
      // ...

      srv.disconnect();
    } catch (Exception e) {
      e.printStackTrace();
    }
    System.exit(0);
  }
Exemple #2
0
  NotifyEmail(String str, String PhoneNumber) {
    // System.out.println(condition);
    StringTokenizer st = new StringTokenizer(str, ">");
    String temp, temp1, temp2, temp3 = "";
    String definedString, msgToSend;

    definedString = "clientName";
    temp = st.nextToken();
    temp1 = temp.substring(1, definedString.length() + 1);
    temp2 = temp.substring(definedString.length() + 2, temp.length());
    if (temp1.compareTo(definedString) != 0)
      System.out.println("Invalid condition. Expected: " + definedString + ", Received: " + temp1);
    // System.out.println("type: " + temp1 + ",value: " + temp2);
    this.userid = temp2;

    definedString = "from";
    temp = st.nextToken();
    temp1 = temp.substring(1, definedString.length() + 1);
    temp2 = temp.substring(definedString.length() + 2, temp.length());
    if (temp1.compareTo(definedString) != 0)
      System.out.println("Invalid condition. Expected: " + definedString + ", Received: " + temp1);
    // System.out.println("type: " + temp1 + ",value: " + temp2);
    this.emailFrom = temp2;

    definedString = "subject";
    temp = st.nextToken();
    temp1 = temp.substring(1, definedString.length() + 1);
    temp2 = temp.substring(definedString.length() + 2, temp.length());
    if (temp1.compareTo(definedString) != 0)
      System.out.println("Invalid condition. Expected: " + definedString + ", Received: " + temp1);
    // System.out.println("type: " + temp1 + ",value: " + temp2);
    this.emailSubject = temp2;

    definedString = "date";
    temp = st.nextToken();
    temp1 = temp.substring(1, definedString.length() + 1);
    temp2 = temp.substring(definedString.length() + 2, temp.length());
    if (temp1.compareTo(definedString) != 0)
      System.out.println("Invalid condition. Expected: " + definedString + ", Received: " + temp1);
    // System.out.println("type: " + temp1 + ",value: " + temp2);
    this.emailDate = temp2;

    definedString = "body";
    temp = st.nextToken();
    temp1 = temp.substring(1, definedString.length() + 1);
    temp2 = temp.substring(definedString.length() + 2, temp.length());
    if (temp1.compareTo(definedString) != 0)
      System.out.println("Invalid condition. Expected: " + definedString + ", Received: " + temp1);
    // System.out.println("type: " + temp1 + ",value: " + temp2);
    this.emailBody = temp2;

    while (st.hasMoreTokens()) {
      String toktemp = st.nextToken();
      System.out.println("Token: " + toktemp);

      StringTokenizer st2 = new StringTokenizer(toktemp, ",");
      if (st2.nextToken().equals("<notificationType")) ;
      else this.emailBody += toktemp;
    }

    System.out.println("userid: " + userid);
    System.out.println("from: " + emailFrom);
    System.out.println("subject: " + emailSubject);
    System.out.println("date: " + emailDate);
    System.out.println("body: " + emailBody);

    msgToSend = new String();
    msgToSend += "From: " + emailFrom + "\nSubject: " + emailSubject + "\nBody: " + emailBody;

    System.out.println("EMAIL: SMS this message: " + msgToSend);

    // PhoneNumber="8587053795";
    System.out.println("phone number: " + PhoneNumber);

    CService Service = new CService("COM11", 57600, "Nokia", "");

    Service.setSmscNumber("+13123149810");

    COutgoingMessage NewSMS = new COutgoingMessage(PhoneNumber, msgToSend);

    try {
      System.out.print("Before Connection");
      Service.connect();

      System.out.print("Connection Done");

      Service.sendMessage(NewSMS);
      System.out.print("Sending Done");

      Service.disconnect();
      System.out.print("Disconnect Done");

    } catch (Exception VisionException) {
      VisionException.printStackTrace();
      try {
        Service.disconnect();
      } catch (Exception e) {

      }
    }
  }