我正在使用Sun WTK运行需要发送和接收SMS的Midlet。 WMA控制台可用于向Midlet发送和接收消息,但我想使用自己的应用程序执行相同的操作。

我做了一些嗅探,并注意到消息是通过UDP从WMA控制台发送到仿真器的。

最佳答案

在WTK中挖出罐子之后,我就能弄清楚如何发送和接收SMS。我必须在应用程序类路径中包含jars kvem.jarkenv.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();
}

09-11 19:30
查看更多