Here is a code that can be used to send SMS's from your GPRS device.
This code was modified from 'SimpleWrite.java' example taken from
Samples of API Documentation. Beware that this code has'nt been tested.
So use it at your own risk.
import java.io.*;
import java.util.*;
import javax.comm.*;
public class SimpleWrite {
static Enumeration portList;
static CommPortIdentifier portId;
static String commands[] =
{"AT+CMGS=1","AT+CMGS=\"9292912345\","Hello there"};
static byte[] newline[]={(byte)13,(byte)10}
static SerialPort serialPort;
static OutputStream outputStream;
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")) //your comm port
{
try {
serialPort = (SerialPort)
portId.open("SimpleWriteApp", 2000);
} catch (PortInUseException e) {}
try {
//get the output stream
outputStream = serialPort.getOutputStream();
//write the commands string to the output stream
for(int i=0;i<commands.length;i++)
{ outputstream.write(commands); // write command
outputstream.write(newline); //write new line
}
outputStream.write(messageString.getBytes());
} catch (IOException e) {}
}
}
}
}
}