我正在尝试使用SMSLib从我的pc向手机发送短信。我正在使用我的诺基亚5130GSM手机发送信息,但它不能工作。这是我正在使用的代码。
package sms;
import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.Message.MessageEncodings;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;
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.com12", "COM12", 115200, "Nokia", "Nokia 5130 XPressMusic USB Modem");
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");
gateway.setSmscNumber("+919886005444");
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();
// Send a message synchronously.
OutboundMessage msg = new OutboundMessage("+917829903913", "Sample msg");
msg.setEncoding(MessageEncodings.ENC7BIT);
msg.setSrcPort(0);
msg.setDstPort(66500);
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();
}
}
}这是我得到的错误信息。请帮助,因为我没有太多的知识,这些。
run:
Example: Send message from a serial gsm modem.
SMSLib: A Java API library for sending and receiving SMS via a GSM modem or other supported gateways.
This software is distributed under the terms of the Apache v2.0 License.
Web Site: http://smslib.org
Version: 3.5.1
log4j:WARN No appenders could be found for logger (smslib).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.PortInUseException: Port currently owned by Unknown Windows Application
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:102)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:114)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189)
at org.smslib.Service$1Starter.run(Service.java:276)
BUILD SUCCESSFUL (total time: 6 seconds)发布于 2012-08-18 00:07:38
确保没有其他应用程序正在侦听COM12。由于您的代码尝试注册不可用的COM12,因此发生了javax.comm.PortInUseException:。
在您将所有必要的jars和dll文件复制到正确的位置后,这应该可以工作。您还需要32位JDK,因此您可能需要下载32位版本的JDK,如果没有其他版本,您将获得java.lang.UnsatisfiedLinkError:
我运行了这段代码,它工作了。还请记住,将setSmscNumber设置为SIM卡提供商的SIM卡看起来仍然是默认的(示例之一)
干杯PB
发布于 2013-06-20 16:51:03
有一个与您的手机相关的应用程序(如诺基亚套件),它可以在PC上运行并与您的手机建立连接当您将手机连接到PC时,请确保所有此类应用程序,并使您的连接只是一个物理连接。
发布于 2016-07-01 09:04:02
在我安装了32位的java版本后,它对我起作用了。还要确保您使用了正确的端口。在我的例子中是com11。

https://stackoverflow.com/questions/9207039
复制相似问题