程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> J2ME >> j2me通過WMA讀取短信

j2me通過WMA讀取短信

編輯:J2ME
import Java.io.IOException;import Javax.microedition.midlet.*;import Javax.microedition.io.*;import Javax.wireless.messaging.*; public class Example extends MIDlet implements MessageListener {    MessageConnection messconn;    int total = 0;    boolean done;      // Initial tests setup and execution.     public void startApp() {        try {            // Get our receiving port conection.            messconn = (MessageConnection)                       Connector.open("sms://:6222");             // Register a listener for inbound messages.            messconn.setMessageListener(this);             // Start a message-reading thread.            done = false;            new Thread(new Reader()).start();         } catch (IOException e) {            // Handle startup errors        }    }      // Asynchronous callback for inbound message.     public void notifyIncomingMessage(MessageConnection conn) {        if (conn == messconn) {            total++;        }
       
     }   // Required MIDlet method - release the connection and // signal the reader thread to terminate.  public void pauseApp() { done = true; try { messconn.close(); } catch (IOException e) { // Handle errors } }   // Required MIDlet method - shutdown. // @param unconditional forced shutdown flag  public void destroyApp(boolean unconditional) { done = true; try { messconn.setMessageListener(null); messconn.close(); } catch (IOException e) { // Handle shutdown errors. } }   // Isolate blocking I/O on a separate thread, so callback // can return immediately.  class Reader implements Runnable {  // The run method performs the actual message reading.  public void run() { while (!done) { try { Message mess = messconn.receive(); } catch ( IOException ioe) { // Handle reading errors } } } }}
    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved