views:

156

answers:

1

Hello all, 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.

Does anyone knows how can I achieve my objective?

Thank you.

+1  A: 

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();  
}
jassuncao