Domanda

sto usando Sun WTK di eseguire una midlet che ha bisogno di inviare e ricevere SMS opzionalmente. console WMA può essere utilizzato per inviare e ricevere messaggi alla midlet, ma mi piacerebbe fare la stessa cosa con la mia propria applicazione.

Ho fatto qualche sniffing, e ho notato che i messaggi sono inviati da UDP dalla console WMA per l'emulatore.

È stato utile?

Soluzione

Dopo aver scavato dentro i barattoli in WTK sono stato in grado di capire come inviare e ricevere SMS. Ho dovuto includere il kvem.jar vasetti e kenv.zip nel classpath dell'applicazione. Testato sotto 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();       
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top