GSMS is a very simple
attempt to send and recieve SMS via a GSM modem. Generally it should
also work correctly with a GPRS modem. You can use:
- A modem as those from Wavecom
- You mobile phone over infra-red (iR)
- Your mobile phone connected to your PC by a cable
Generally all newer phones support their use as a GSM Modem so check
with your phone manual.
In all cases you need to know the Serial Port you connect your device
to, such as COM2,COM3 etc and then connect to it.
To use this API you need the Java Comm API that you
can download from java.sun.com. Follow CLOSELY the instructions for
installing the comm API otherwise it wont work. Look for the jdk1.2.html
file for installing help when using J2SE1.2 and later.
| To use GSMS simply use the code snippets
as below: |
import java.io.*;
import java.util.*;
import javax.comm.*;
//import packages
....
public static void main(String[] args)
{
GSMModem myModem;
try
{
//
//
//SEND
//
//connect
myModem=new GSMModem("COM2",CONST.CONNECT_BAUD_9600);
//init
myModem.init();
//see wat modem i have
System.out.println(myModem.specs());
//send sms
myModem.setSMSMode(1);//send as text
myModem.flushInput();//clear reply in input stream
System.out.print("Sending...");
//myModem.sendSMS("99999999","sending as a text");
System.out.println(myModem.reply());
//close connection
myModem.disconnect();
//
//
//RECV
Thread.sleep(5000);//just to relax sim card for a while =),
no need if using independently
//
//connect
myModem=new GSMModem("COM2",CONST.CONNECT_BAUD_9600);
//init
myModem.init();
//show sms on sim
LinkedList ll=myModem.showAllSMS();
if(ll.size()==0) System.out.println("No msgs");
for(int i=0;i<ll.size();i++)
System.out.println(ll.get(i));
//how to delete
//myModem.deleteSMS(((SMSText)ll.get(0)).getIndex());
//close connection
myModem.disconnect();
}catch(Exception e) {System.out.println(e); }
}
...
//basic demonstration
|
| You can generate JavaDocs using the source or view
online. |
Whats still missing/bugs:
- PDU Format: Cant handle PDU format, uses text only (AT+CMGF=1)
- HEX:Some bug in converting GSM 7 Bit to ASCII - does not do correctly
for the funny characters, pls send me a corrected version if you
figure it out.
Download Java Source
Click here for
more about SMS. Licensed as GPL, I'd appreciate if you send to
me any extensions you write using this package.
|