我正在使用Sun WTK运行需要发送和可选接收短信的midlet。 WMA控制台可用于向midlet发送和接收消息,但我想使用自己的应用程序执行相同的操作。
我做了一些嗅探,并注意到消息是由UDP从WMA控制台发送到模拟器的。
答案 0 :(得分:1)
在WTK中挖掘罐子后,我能够弄清楚如何发送和接收短信。我必须在应用程序类路径中包含jar kvem.jar
和kenv.zip
。在Linux下测试。
public static void main(String[] args) throws IOException, PhoneNumberNotAvailableException, InterruptedException {
System.setProperty("kvem.home", "/home/jassuncao/usr/WTK2.5.2");
WMAClient wmaClient = WMAClientFactory.newWMAClient(null, 4);
wmaClient.connect();
wmaClient.setMessageListener(new MessageListener() {
@Override
public void notifyIncomingMessage(WMAClient wmaclient) {
try {
System.out.println("Message received:"+wmaclient.receive());
} catch (IOException e) {
e.printStackTrace();
}
}
});
System.out.println("This number "+wmaClient.getPhoneNumber());
String[] receivers = wmaClient.getKnownReceivers();
for (String receiver : receivers) {
System.out.println("Sending SMS to "+receiver);
Message msg = new Message("Hello world!!");
msg.setFromAddress("sms://"+wmaClient.getPhoneNumber());
msg.setToAddress("sms://"+receiver);
//It seems the ports must be set AFTER the address to work
msg.setToPort(50000);
msg.setFromPort(50000);
wmaClient.send(msg);
}
System.in.read();
wmaClient.unregisterFromServer();
}