public void run() { String address = destinationAddress; MessageConnection smsconn = null; try { /** Open the message connection. */ smsconn = (MessageConnection)Connector.open(address); TextMessage txtmessage = (TextMessage)smsconn.newMessage(MessageConnection.TEXT_MESSAGE); txtmessage.setAddress(address); txtmessage.setPayloadText(messageBox.getString()); smsconn.send(txtmessage); } catch (Throwable t) { System.out.println("Send caught: "); t.printStackTrace(); } if (smsconn != null) { try { smsconn.close(); } catch (IOException ioe) { System.out.println("Closing connection caught: "); ioe.printStackTrace(); } } }code ref: J2ME WMAdemo PS: 請把 port的地方拿掉, 因為我們沒有模擬Receive端透過port來做連接.
2010年4月11日 星期日
J2ME Wireless Toolkit WMA (JSR102)
Wireless Toolkit for JSR
J2ME 的Entry point (commandAction),像是 *.java 的main. 其中定義了App start, pause,destroy.
可以在內部填入我們所要的method...
public void commandAction(Command cmd, Displayable disp) {}
protected void startApp() { }
protected void pauseApp() {}
protected void destroyApp(boolean bool) {}
在Entry point (commandAction)會check 現在所輸入的command,如Exit , Send Message....
每個command 會有對應的class, 有點像是Action listen的動作.
底下是 SMS Sender的範例,會定義要傳的Address(Cell Phone Number), Message 內容...
SMS Sender.java
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言