在自定义应用程序中接收从 WTK 模拟器发送的 SMS

发布于 2024-08-10 22:05:45 字数 144 浏览 5 评论 0原文

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

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

I'm using Sun WTK to run a midlet that needs to send and optionally receive SMS. WMA console can be used to send and receive messages to the midlet but I'd like to do the same thing using my own application.

I have done some sniffing, and noticed that the messages are sent by UDP from the WMA console to the emulator.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

×眷恋的温暖 2024-08-17 22:05:45

在深入研究 WTK 的 jar 后,我能够弄清楚如何发送和接收 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();       
}

After digging inside the jars in WTK I was able to figure out how to send and receive SMS. I had to include the jars kvem.jar and kenv.zip in the application classpath. Tested under 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();       
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文