smslib-java-v3.0.1
所属分类:软件设计/软件工程
开发工具:Java
文件大小:609KB
下载次数:28
上传日期:2007-11-09 01:54:23
上 传 者:
管理员
说明: 华为编程开发规范与案例, 华为编程开发规范与案例,华为编程开发规范与案例
(Huawei Programming norms and cases, Huawei Programming norms and cases, Huawei norms Programming and Case)
文件列表:
build (0, 2007-06-24)
build-libraries.xml (789, 2007-06-24)
build.properties (172, 2007-06-24)
build.xml (3628, 2007-07-01)
build\Introduction.html (10553, 2007-06-24)
build\SMSLib.mf (159, 2007-06-24)
CHANGELOG (549, 2007-07-01)
dist (0, 2007-07-01)
dist\classes (0, 2007-07-01)
dist\classes\examples (0, 2007-07-01)
dist\classes\examples\bulksms (0, 2007-07-01)
dist\classes\examples\bulksms\SendMessage.class (2159, 2007-07-01)
dist\classes\examples\clickatell (0, 2007-07-01)
dist\classes\examples\clickatell\SendMessage$OutboundNotification.class (1185, 2007-07-01)
dist\classes\examples\clickatell\SendMessage.class (3068, 2007-07-01)
dist\classes\examples\modem (0, 2007-07-01)
dist\classes\examples\modem\SendMessage$OutboundNotification.class (1160, 2007-07-01)
dist\classes\examples\modem\SendMessage.class (3333, 2007-07-01)
dist\classes\examples\routing (0, 2007-07-01)
dist\classes\examples\routing\ByDestinationRouting.class (2067, 2007-07-01)
dist\classes\examples\routing\TrivialRouting.class (1545, 2007-07-01)
dist\classes\misc (0, 2007-07-01)
dist\classes\misc\CommTest.class (3017, 2007-07-01)
dist\classes\org (0, 2007-07-01)
dist\classes\org\smslib (0, 2007-07-01)
dist\classes\org\smslib\athandlers (0, 2007-07-01)
dist\classes\org\smslib\athandlers\AbstractATHandler.class (4522, 2007-07-01)
dist\classes\org\smslib\athandlers\ATHandler$1.class (1823, 2007-07-01)
dist\classes\org\smslib\athandlers\ATHandler.class (10354, 2007-07-01)
dist\classes\org\smslib\athandlers\ATHandler_MultiTech.class (1808, 2007-07-01)
dist\classes\org\smslib\athandlers\ATHandler_Siemens_M55.class (515, 2007-07-01)
dist\classes\org\smslib\athandlers\ATHandler_Siemens_S55.class (453, 2007-07-01)
dist\classes\org\smslib\athandlers\ATHandler_Siemens_TC35.class (881, 2007-07-01)
dist\classes\org\smslib\athandlers\ATHandler_Wavecom.class (618, 2007-07-01)
dist\classes\org\smslib\balancing (0, 2007-07-01)
dist\classes\org\smslib\balancing\LoadBalancer.class (1860, 2007-07-01)
... ...
// ReadMessages.java - Sample application.
//
// This application shows you the basic procedure needed for reading
// SMS messages from your GSM modem, in synchronous mode.
//
// Operation description:
// The application setup the necessary objects and connects to the phone.
// As a first step, it reads all messages found in the phone.
// Then, it goes to sleep, allowing the asynchronous callback handlers to
// be called. Furthermore, for callback demonstration purposes, it responds
// to each received message with a "Got It!" reply.
//
// Tasks:
// 1) Setup Service object.
// 2) Setup one or more Gateway objects.
// 3) Attach Gateway objects to Service object.
// 4) Setup callback notifications.
// 5) Run
package examples.modem;
import org.smslib.*;
import java.util.*;
import org.smslib.gateway.ModemGateway;
public class ReadMessages
{
private Service srv;
public void doIt() throws Exception
{
LinkedList msgList;
// Create the notification callback method for Inbound & Status Report
// messages.
InboundNotification inboundNotification = new InboundNotification();
// Create the notification callback method for incoming voice calls.
CallNotification callNotification = new CallNotification();
try
{
System.out.println("Example: Read messages from a serial gsm modem.");
System.out.println(Library.LIB_INFOTEXT);
System.out.println("Version: " + Library.LIB_VERSION + "." + Library.LIB_RELEASE + "." + Library.LIB_SUBRELEASE);
// Create new Service object - the parent of all and the main interface
// to you.
srv = new Service();
// Create the Gateway representing the serial GSM modem.
// If you prefer to use an IP modem, replace the port (i.e. COM1) with
// the IP of the modem,
// and the baudrate (i.e. 57600) with the listening port of the modem.
// Example: ModemGateway gateway = new ModemGateway("modem.ip",
// "192.168.10.20", 5000, "MultiTech", "", srv);
ModemGateway gateway = new ModemGateway("modem.com1", "COM1", 57600, "Nokia", "6310i", srv.getLogger());
// Do we want the Gateway to be used for Inbound messages? If not,
// SMSLib will never read
// messages from this Gateway.
gateway.setInbound(true);
// Do we want the Gateway to be used for Outbound messages? If not,
// SMSLib will never send
// messages from this Gateway.
gateway.setOutbound(true);
gateway.setSimPin("0000");
// Set up the notification methods.
gateway.setInboundNotification(inboundNotification);
gateway.setCallNotification(callNotification);
// Add the Gateway to the Service object.
srv.addGateway(gateway);
// Similarly, you may define as many Gateway objects, representing
// various GSM modems, add
// them in the Service object and control all of them.
// Start! (i.e. connect to all defined Gateways)
srv.startService();
System.out.println();
System.out.println("Modem Information:");
System.out.println(" Manufacturer: " + gateway.getManufacturer());
System.out.println(" Model: " + gateway.getModel());
System.out.println(" Serial No: " + gateway.getSerialNo());
System.out.println(" SIM IMSI: " + gateway.getImsi());
System.out.println(" Signal Level: " + gateway.getSignalLevel() + "%");
System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%");
System.out.println();
// Read Messages. The reading is done via the Service object and
// affects all Gateway
// objects defined. This can also be more directed to a specific
// Gateway - look the
// JavaDocs for information on the Service method calls.
msgList = new LinkedList();
srv.readMessages(msgList, InboundMessage.MessageClass.All);
for (int i = 0; i < msgList.size(); i++)
System.out.println(msgList.get(i));
// Sleep now. Emulate real world situation and give a chance to the
// notifications
// methods to be called in the event of message or voice call
// reception.
System.out.println("Now Sleeping - Hit to terminate.");
System.in.read();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
srv.stopService();
}
}
public class InboundNotification implements IInboundMessageNotification
{
public void received(String gatewayId, Message.MessageType msgType, String memLoc, int memIndex)
{
LinkedList msgList;
switch (msgType)
{
case INBOUND:
System.out.println(">>> New Inbound message detected from Gateway: " + gatewayId + " : " + memLoc + " @ " + memIndex);
try
{
// Read...
msgList = new LinkedList();
srv.readMessages(msgList, InboundMessage.MessageClass.Unread, gatewayId);
for (int i = 0; i < msgList.size(); i++)
System.out.println(msgList.get(i));
// ...and reply.
// for (int i = 0; i < msgList.size(); i ++)
// srv.sendMessage(new
// OutboundMessage(msgList.get(i).getOriginator(), "Got it!"),
// gatewayId);
}
catch (Exception e)
{
System.out.println("Oops, some bad happened...");
e.printStackTrace();
}
break;
case STATUSREPORT:
System.out.println(">>> New Status Report message detected from Gateway: " + gatewayId + " : " + memLoc + " @ " + memIndex);
break;
}
}
}
public class CallNotification implements ICallNotification
{
public void received(String gatewayId, String callerId)
{
System.out.println(">>> New call detected from Gateway: " + gatewayId + " : " + callerId);
}
}
public static void main(String args[])
{
ReadMessages app = new ReadMessages();
try
{
app.doIt();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
近期下载者:
相关文件:
收藏者: