sending sms to mobile from pc using java [closed]
- by sjohnfernandas
hi i need to send sms from pc to mobile phone can u people guide me to achieve? i used the following code to send sms to a mobile from pc but i did not get any output and also not getting any error so guide me and point out the mistakes what i have done.
package mobilesms;
import java.io.;
import java.util.;
import javax.comm.*;
import java.io.IOException;
import java.util.Properties;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
public class ReadSimple implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;
OutputStream outputstream;
InputStream inputStream;
SerialPort serialPort;
Thread readThread;
public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM1")) {
System.out.println("Found port:COM1 ");
ReadSimple reader = new ReadSimple();
}
}
}
}
public ReadSimple() {
try {
serialPort = (SerialPort) portId.open("ReadSimpleApp",500);
} catch (PortInUseException e) {
System.out.println(e);
}
try {
inputStream = serialPort.getInputStream();
OutputStream out=serialPort.getOutputStream();
String line="";
line="AT"+"r\n";
out.write(line.trim().getBytes());
line="";
line="AT+CMGS=7639808583"+"\r\n";
out.write(line.trim().getBytes());
System.out.print(line);
line="helloworld";
//line=”ATD 996544325;”+”\r\n”;
out.write(line.trim().getBytes());
} catch (IOException e) {
serialPort.close();
System.out.println(e);
}
// catch(InterruptedException E){E.printStackTrace();}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {System.out.println(e);}
serialPort.notifyondataavailable(true);
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {System.out.println(e);}
readThread = new Thread(this);
readThread.start();
}
public void run() {
try {
Thread.sleep(200);
} catch (InterruptedException e) {System.out.println(e);}
}
public void serialEvent(SerialPortEvent event) {
switch(event.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_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[10];
try {
while (inputStream.available() 0) {
int numBytes = inputStream.read(readBuffer);
}
System.out.println(new String(readBuffer));
} catch (IOException e) {System.out.println(e);}
break;
}
}
}