我正在尝试使用 smslib api 发送消息,老实说,我对此知之甚少,所以我下载了一个示例项目并将库放在相应的位置。我发送消息的课程是:
public class SendMessage{
public void doIt() throws Exception
{
OutboundNotification outboundNotification = new OutboundNotification();
System.out.println("Example: Send message from a serial gsm modem.");
System.out.println(Library.getLibraryDescription());
System.out.println("Version: " + Library.getLibraryVersion());
SerialModemGateway gateway = new SerialModemGateway("modem.com4", "COM4", 9600, "", "");
gateway.setInbound(true);
gateway.setOutbound(true);
Service.getInstance().setOutboundMessageNotification(outboundNotification);
Service.getInstance().addGateway(gateway);
Service.getInstance().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() + " dBm");
System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%");
System.out.println();
OutboundMessage msg = new OutboundMessage("contact_num", "Hello from SMSLib!");
Service.getInstance().sendMessage(msg);
System.out.println(msg);
System.out.println("Now Sleeping - Hit <enter> to terminate.");
System.in.read();
Service.getInstance().stopService();
}
public class OutboundNotification implements IOutboundMessageNotification
{
public void process(AGateway gateway, OutboundMessage msg)
{
System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
System.out.println(msg);
}
}
public static void main(String args[])
{
SendMessage app = new SendMessage();
try
{
app.doIt();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
在执行该行
Service.getInstance().startService();
我得到一个例外:
org.smslib.GatewayException:通讯库异常:java.lang.RuntimeException:在 org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:102) 在 org.smslib.modem.AModemDriver.connect(AModemDriver) 的 javax.comm.NoSuchPortException .java:114) 在 org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189) 在 org.smslib.Service$1Starter.run(Service.java:277)
好吧,这必须发生,因为我没有 GSM 调制解调器,所以我有几个问题。
我可以把我的 android 手机变成 gsm 调制解调器吗?
SerialModemGateway("modem.com4", "COM4", 9600, "", ""); 中的 modem.com4 是什么?意思是 。
我搜索了很多关于如何将手机变成 gsm 调制解调器的方法,但没有运气。