|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--com.unipro.smlib.SmsManager
Note: In the next version of SMLib this class will not extend java.lang.Thread and implement java.lang.Runnable
Please, plan your business logic accordingly
Main class of SMLib.
// Import SMLib classes
import com.unipro.smlib.*;
public class test {
public static void main(String[] s) {
// Create an instance of SmsManager class
SmsManager smsManager = SmsManager.getInstance();
try {
// Initialize library. Set your port settings in the new Configurator object
smsManager.init(new Configurator(Configurator.PORT_COM1,Configurator.BAUD_19200));
} catch (Exception e) {
// Handle exceptions of initializations here
}
try {
// Create new out message. Pass recipient number, SMSC number and message text to the constructor
// Send the message using sendMessage method
smsManager.sendMessage(new OutMessage("79029261105","79029261405","Hello World!"));
} catch (Exception e) {
// Handle exceptions of sending here
}
// Stop the library
smsManager.close();
}
}
import com.unipro.smlib.*;
class TestListener implements SmsListener {
// Method to process the in message
public void processMessage(InMessage mess) {
System.out.println("New message is received from "+mess.getSenderNumber()+" '"+mess.getText()+"'");
}
}
Modify the previous code to add the listener to SmsManager.
smsManager.addMessageListener(new TestListener());
// Import SMLib classes
import com.unipro.smlib.;
public class SendMessage {
public static void main(String[] s) {
// Create an instance of SmsManager class
SmsManager smsManager1 = SmsManager.getInstance();
SmsManager smsManager2 = SmsManager.getInstance();
try {
// Initialize library
// Set your port settings in the new Configurator object
smsManager1.init(new Configurator(
Configurator.PORT_COM1,Configurator.BAUD_19200
));
smsManager2.init(new Configurator(
Configurator.PORT_COM2,Configurator.BAUD_19200
));
} catch (Exception e) {
// Handle exceptions of initializations here
}
try {
smsManager1.addMessageListener(new TestListener());
smsManager2.addMessageListener(new TestListener());
} catch (TooManyListenersException e) {}
}
}
Field Summary | |
static int |
MAX_MOB_SIZE
|
static int |
SMLIB_CLOSED
One of statuses that can be returned by getStatus method. SMLib is not initialized. |
static int |
SMLIB_DISCONNECT
One of statuses that can be returned by getStatus method. SMLib was initialized but after that cable was unplugged. It is possible to return SMLib to the correct state by reconnecting the cable. |
static int |
SMLIB_ERROR_CONNECT
One of statuses that can be returned by getStatus method. SMLib was initialized but after that cable was unplugged with error. |
static int |
SMLIB_ERROR_PORT
One of statuses that can be returned by getStatus method. SMLib was initialized but after that error of communication port occurred. It is necessary to close SMLib and initialize it again. |
static int |
SMLIB_INIT_NONRECEPT
One of statuses that can be returned by getStatus method. SMLib was initialized and isn't receiving messages. |
static int |
SMLIB_INIT_RECEPT
One of statuses that can be returned by getStatus method. SMLib was initialized and is receiving messages. |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Method Summary | |
void |
addACKListener(ACKListener listener)
Registers listener object that can process input ACKs. |
void |
addMessageListener(SmsListener listener)
Registers listener object that can process input messages. |
void |
allowReception(boolean al)
Allows or forbids reception of input messages and ACKs. It can be able to refuse input messages and ACKs by calling allowReception(false). |
void |
close()
Stops SMLib: stops 2 internal threads that were created by init() method and release COM port. |
void |
deleteACKListener()
Deletes ACK listener (About listeners). |
void |
deleteMessageListener()
Deletes messages listener (About listeners). |
static SmsManager |
getInstance()
Creates SmsManager's instance. |
int |
getStatus()
Gets the status of SMLib. |
void |
init(Configurator pc)
Initializes SMLib with the specified settings. This method initializes two threads: first runs java comm API and second runs method for getting SMS from mobile phone. |
void |
run()
|
int |
sendMessage(OutMessage SMMessage)
Sends an SMS message. |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int SMLIB_CLOSED
public static final int SMLIB_INIT_RECEPT
public static final int SMLIB_INIT_NONRECEPT
public static final int SMLIB_DISCONNECT
public static final int SMLIB_ERROR_CONNECT
public static final int SMLIB_ERROR_PORT
public static final int MAX_MOB_SIZE
Method Detail |
public int getStatus()
public static SmsManager getInstance()
public void init(Configurator pc) throws PortConnectionException, MobileException
pc
- settings of COM port and pools, if pc=null then default settings is used. PortConnectionException
- if there are any problems with COM port or data cable
MobileException
- if there are any problems with mobile AT interface.
public void allowReception(boolean al)
al
- true allows, false forbid the reception. True by default.public int sendMessage(OutMessage SMMessage) throws PortConnectionException, SendException
OutMessage
- object that represents output message.SendException
- if there are problems with sending message from mobile phone or error of sending occurred (see more in SendException description).PortConnectionException
- if there is no connection with mobile phone:
mobile phone is not responding during long period of time (about 30 sec).public void addMessageListener(SmsListener listener) throws java.util.TooManyListenersException
SmsListener
- message listener.java.util.TooManyListenersException
- if SmsListener is already registered in the SmsManager.public void addACKListener(ACKListener listener) throws java.util.TooManyListenersException
ACKListener
- message listenerjava.util.TooManyListenersException
- if ACKListener is already registered in the SmsManager.public void deleteMessageListener()
public void deleteACKListener()
public void close()
public void run()
run
in class java.lang.Thread
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |