1

我正在使用 Sun WTK 运行需要发送和接收 SMS 的 midlet。WMA 控制台可用于向 midlet 发送和接收消息,但我想使用我自己的应用程序做同样的事情。

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

4

1 回答 1

1

在 WTK 中挖掘罐子后,我能够弄清楚如何发送和接收 SMS。我必须包含罐子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();       
}
于 2009-11-13T12:11:23.030 回答