Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Magazine send sms from pc to mobile via gsm modem in java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


shreyans
send sms from pc to mobile via gsm modem in java
1 Answer(s)      3 years and 10 months ago
Posted in : Java Magazine


pls send me the code to send sms from pc to mobile via GSM modem programmed in JAVA


Advertisement
View Answers

March 7, 2011 at 1:16 AM


<p>here is the answer.....
can u pls help me to retrieve message from mobile to java program...
import java.io.*;
import java.util.*;
import javax.comm.*;</p>

<p>public class GSMConnect implements SerialPortEventListener,
  CommPortOwnershipListener {</p>

<p>  private String comPort = "COM3"; // This COM Port must be connect with GSM Modem or your mobile phone
  private String messageString = "";
  private CommPortIdentifier portId = null;
  private Enumeration portList;
  private InputStream inputStream = null;
  private OutputStream outputStream = null;
  private SerialPort serialPort;</p>

<p>  /** Creates a new instance of GSMConnect */
  public GSMConnect(String comm) {</p>

<pre class="prettyprint">this.comPort = comm;
</code></pre>

<p>  }</p>

<p>  public boolean init() {
    portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
      portId = (CommPortIdentifier) portList.nextElement();
      if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
        if (portId.getName().equals(comPort)) {
            System.out.println("init");
          return true;
        }
      }
    }
    return false;
  }</p>

<p>  public void checkStatus() {
    send("AT+CREG?\r\n");
  }</p>

<p>  public void dial(String phoneNumber) {
    try {
//dial to this phone number
      messageString = "ATD" + phoneNumber + ";\n\r";
      outputStream.write(messageString.getBytes());
    } catch (IOException e) {
      e.printStackTrace();
    }
  }</p>

<p>  public void send(String cmd) {
    try {
      outputStream.write(cmd.getBytes());
    } catch (IOException e) {
      e.printStackTrace();
    }
  }</p>

<p>  public void sendMessage(String phoneNumber, String message) {
    send("AT+CMGS=\"" + phoneNumber + "\"\r\n");
    send(message + '\032');
  }</p>

<p>  public void hangup() {
    send("ATH\r\n");
  }</p>

<p>  public void connect() throws NullPointerException {
    if (portId != null) {
      try {
        portId.addPortOwnershipListener(this);
        serialPort = (SerialPort) portId.open("MobileGateWay", 2000);
      } catch (PortInUseException e) {
        e.printStackTrace();
      }</p>

<pre class="prettyprint">  try {
    inputStream = serialPort.getInputStream();
    outputStream = serialPort.getOutputStream();
  } catch (IOException e) {
    e.printStackTrace();
  }

  try {
    /** These are the events we want to know about*/
    serialPort.addEventListener(this);
    serialPort.notifyOnDataAvailable(true);
  } catch (TooManyListenersException e) {
    e.printStackTrace();
  }
</code></pre>

<p>//Register to home network of sim card</p>

<pre class="prettyprint">  send("ATZ\r\n");

} else {
  throw new NullPointerException("COM Port not found!!");
}
</code></pre>

<p>  }</p>

<p>  public void serialEvent(javax.comm.SerialPortEvent serialPortEvent) {
    switch (serialPortEvent.getEventType()) {
      case SerialPortEvent.BI:
      case SerialPortEvent.OE:
      case SerialPortEvent.FE:
      case SerialPortEvent.PE:
      case SerialPortEvent.CD:
      case SerialPortEvent.CTS:
      case SerialPortEvent.DSR:
      case SerialPortEvent.RI:
      case SerialPortEvent.OUTPUT<em>BUFFER</em>EMPTY:
      case SerialPortEvent.DATA_AVAILABLE:</p>

<pre class="prettyprint">    byte[] readBuffer = new byte[2048];
    try {
      while (true)
      {
        int numBytes = inputStream.read(readBuffer);
      }
</code></pre>

<p>//print response message
          //System.out.print(new String(readBuffer));
        } catch (IOException e) {
        }
        break;
    }
  }</p>

<p>  public void ownershipChange(int type) {
    switch (type) {
      case CommPortOwnershipListener.PORT_UNOWNED:
        System.out.println(portId.getName() + ": PORT_UNOWNED");
        break;
      case CommPortOwnershipListener.PORT_OWNED:
        System.out.println(portId.getName() + ": PORT_OWNED");
        break;
      case CommPortOwnershipListener.PORT<em>OWNERSHIP</em>REQUESTED:
        System.out.println(portId.getName() + ": PORT_INUSED");
        break;
    }</p>

<p>  }</p>

<p>  public static void main(String args[]) {
    GSMConnect gsm = new GSMConnect("COM3");
    if (gsm.init()) {
      try {
        gsm.connect();
        gsm.checkStatus();
        Thread.sleep(5000);
        gsm.sendMessage("+9400530373", "hai dis is test");
        //gsm.dial("+9400530373");
        Thread.sleep(20000);
        gsm.hangup();
       // gsm.dial("+9400530373");
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else {
      System.out.println("Can't init this card");
    }
  }
}</p>


Related Tutorials/Questions & Answers:
send sms from pc to mobile via gsm modem connected to pc in java
send sms from pc to mobile via gsm modem connected to pc in java  pls send me the code to send sms from pc to mobile via GSM modem programmed in JAVA
send sms from pc to mobile via gsm modem in java
send sms from pc to mobile via gsm modem in java  pls send me the code to send sms from pc to mobile via GSM modem programmed in JAVA........ can u pls help me to retrieve message from mobile to java program... import
Advertisements
send sms from pc to mobile
send sms from pc to mobile  java program to send sms from pc to mobile
SMS Receiving JAVA application from GSM modem
SMS Receiving JAVA application from GSM modem  Hey does any one having SMS reeving JAVA application
SMS receive and sending throught PC using GSM modem
SMS receive and sending throught PC using GSM modem  How to send and receive SMS from PC using GSM modem Want code please could some one helpme
sms from pc to mobile
sms from pc to mobile  Sir I am developing a website and i need a code to send sms on any mobile from the wbesite.pls help me. thanx in advance
sms from pc to mobile
sms from pc to mobile  Sir I am developing a website and i need a code to send sms on any mobile from the wbesite.pls help me. thanx in advance
Code to Send SMS From PC to Mobile using Internet
Code to Send SMS From PC to Mobile using Internet  import... !!"); } } I am Using This code to send SMS from PC to Mobile Phone... number should be present to send SMS."); } String temp
Code to Send SMS From PC to Mobile using Internet
Code to Send SMS From PC to Mobile using Internet  import... !!"); } } I am Using This code to send SMS from PC to Mobile Phone... number should be present to send SMS."); } String temp
Code to Send SMS From PC to Mobile using Internet
Code to Send SMS From PC to Mobile using Internet  import... !!"); } } I am Using This code to send SMS from PC to Mobile Phone... number should be present to send SMS."); } String temp
how to send sms on mobile
how to send sms on mobile  send sms on mobile by using struts + spring
How to send sms alerts to mobile using java?
How to send sms alerts to mobile using java?  Hi i have used the Code to send message on mobile using java code, it is not working - COM2 javax.comm.NoSuchPortException at javax.comm.CommPortIdentifier.getPortIdentifier
how to send sms from my website to mobile of particular user.
how to send sms from my website to mobile of particular user.  i had... with their mobile number daily one health tip is to sent to their respective mobiles.. so can u tell the process and how to implemnt this using java
sending sms from a remote pc - MobileApplications
sending sms from a remote pc  I have a remote pc that has a localhost server(tomcat).I want to know whether it is possible for me to send an sms from this server(my pc) to a mobile phone.If so can i have the sample code
how to send sms on mobile and email using java code
how to send sms on mobile and email using java code  hi.... I am developing a project where I need to send a confirmation/updation msg on clients mobile and also an email on their particular email id....plz help me to find
sms(gsm) - MobileApplications
sms(gsm)  I heard that using GSM we can send only 10sms per second. Is it rigt? is there any other way so that we can send 250 SMS per second
sending sms from laptop to mobile
sending sms from laptop to mobile   sending sms from laptop to mobile for multi users
sending sms from laptop to mobile
sending sms from laptop to mobile   sending sms from laptop to mobile for multi users
Dialling from computer with other phone via modem card
Dialling from computer with other phone via modem card  Hello everyone I would like to create a c# desktop application that has ability to call a phone number through a modem connected in the computer. During research I ended up
Sms to mobile using java application
Sms to mobile using java application  Hi, i want to send sms to mobile using java application. But i dont have any idea for this procees. So kindly suggest me any ideas. regards vijayalakshmi
TYBsc IT final project (MOBILE BASED SMS SEARCH ENGIN)
TYBsc IT final project (MOBILE BASED SMS SEARCH ENGIN)  How to send and receive a msg from jsp servlet program to mobile phone using gsm vodafone modem? Pls give me fast reply becoz my porject(TYBsc IT)final has not been
Sms Progam
Sms Progam  i have to send SMS from pc to mobile in my java program
SMS Send and Recieve - JSP-Servlet
SMS Send and Recieve  How can i embedded SMS service to send and receive SMS from mobile to my application
Vehicle Tracking System using GPS and GSM modem project
Vehicle Tracking System using GPS and GSM modem project  what is the source coding of Vehicle Tracking System using GPS and GSM modem
Sending SMS From Java Programs
Sending SMS From Java Programs  I want to develop and application to send sms from my computer, can someone please help me, like tell me where to start and what i need
sms - Java Server Faces Questions
sms  hello .... can any body tell me how to send sms from pc to mobile using java ..an if possible please give me the code in jsp..... my email id is:bharachaitanya@yahoo.co.in
TYBsc IT final project (MOBILE BASED SMS SEARCH ENGIN)
TYBsc IT final project (MOBILE BASED SMS SEARCH ENGIN)  How to send sms pc to mobile using JSP & Servelet
how to call from pc to telephone in java - MobileApplications
how to call from pc to telephone in java  Hi, presently I am working on "make a call from pc to telephone" in java. I am unable to procceed how to start. I am new this technoloy.Please give me some valuable suggestions how
Java SMS Progam
Java SMS Progam  Hai to all, I have to send SMS alerts in my applicaton in java technology with out using any gateways and GSM Modems. Thanks
j2me sms coding - Java Beginners
j2me sms coding  please send me the source code to send sms and making a call from mobile
code to send sms alerts using jsp online
code to send sms alerts using jsp online  I am new to mobile aplication development. pls send me the code for sms alerts after clicking the button
 

 

 

DMCA.com