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

Have Programming Question? Ask it here!
 
 
 


shreyans
send sms from pc to mobile via gsm modem in java
1 Answer(s)      3 years and 5 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 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
Sms Progam
Sms Progam  i have to send SMS from pc to mobile in my java program
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
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
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
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
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
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
SMS sending questions using java - MobileApplications
SMS sending questions using java  am doing project sending SMS from pc.how to send bulk SMS ?i achive sending single SMS .but i would like to send bulk SMS.am using mobile phone for sending SMS.is it possible sending bulk SMS
SMS using Java
;This is regarding your post for sending SMS from a PC( http://www.roseindia.net/answers/viewqa/Java-Beginners/15745-Sms-to-mobile-using-java-application.html ) How...SMS using Java  I am having a concern , where is the main class
sending sms with help of java - JavaMail
sending sms with help of java  hi can u plz help me to learn how to send sms with help of java. waiting for your reply
java code for sending sms - JSP-Servlet
java code for sending sms  hello sir, I want a code for sending sms on mobile . please send me if u have this Thanks & regards Dharmendra
java not run on my pc
java not run on my pc  i have installed java in pc but when i run and compile any program the massage is display that 'javac' is not recognized as an internal or external command
xml to html via java
xml to html via java  how to read xml into html using java code
How to send message in struts on mobile - Struts
How to send message in struts on mobile  Hello Experts, How can i send messages on mobile i am working on strus application and i want to send message from jsp
java sms problem
java sms problem  i am developing web site in which i have to maintain sms system where one can message his/her detail and it should be stored in the database.please give me some idea how to maintain it as i am beginner.Thank you
receive message from mobile to java program
receive message from mobile to java program  i got a code to receive message....but wen i receive it its showing a string which is not readable... if possible please edit dis code to retreive the origianl string message.... here
What is GSM ?
What is GSM ?  hello, What is GSM ?   hiii, The Global System for Mobile Communications (GSM) is a wireless network system that is widely used in Europe, Asia, and Australia. GSM is used at three different
sms prob
sms prob  Hi, i want to send sms to mobile in calling mode with voice using java struts 2.0 code. But i dont have any idea for this procees. So kindly suggest me any ideas
VoIP Modem
. The Net2Phone software is installed on a PC that is connected to the Internet via a dial-up... telephone plugged into the modem make calls over the Internet via Net2Phone's... VoIP Modem Zoom X5v ADSL VoIP Modem The Zoom X5v Model 5565
SMS Parsing
SMS Parsing  Hello Friends I am working on the code in which The text message(SMS) is send to receiver. There are two webpages UDHCSender &... as: sender mobile number SMS received but in the SMS received it shows
how to send the content of jtextarea from netbeans IDE to webpage's textarea in java
how to send the content of jtextarea from netbeans IDE to webpage's textarea in java   Hi, i m interested to send the content of my jtextarea which... that in java? or what are the other way to do
Accessing database with JDBC via Java
Accessing database with JDBC via Java  How to access a database with JDBC via Java application?   Accessing database with JDBC through Java JDBC Example to access Database import java.sql.*; public class JdbcConnect
How to send boolean array to servlet from java application?
How to send boolean array to servlet from java application?  Hi, I want to send randomly generated array of boolean values. I used Random function and boolean array length to generate values. My question is I want to send
swing sms
swing sms  HOW TO SEND SMS MESSAGE FROM SWING USING SQL DATABASE
how to establish connection b/w java app and mobile phone
to send SMS from our phone to a java application situated on a remote server... i.e.., we don't know how to send and receive SMS to java server.We don't know what...how to establish connection b/w java app and mobile phone  hello
how to create a create personalized SMS for each recipient - Java Server Faces Questions
based sms platform that send different message text to different mobile...how to create a create personalized SMS for each recipient   i am doing a project at college, i am using java server faces technology. I am having
 

 

 

DMCA.com