⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smsreceive.java

📁 用Java/C#开发手机程序及移动应用光盘代码。J2ME核心类及MIDlet类;基于Java开发MIDlet程序;图形处理及低级事件处理;多线程编程;即时消息传送;I/O及网络编程;数据库编程;多媒体
💻 JAVA
字号:
import javax.microedition.midlet.*;import javax.microedition.io.*;import javax.microedition.lcdui.*;import javax.wireless.messaging.*;import java.io.IOException;public class SMSReceive extends MIDlet     implements CommandListener, Runnable, MessageListener {       Command exitCommand  = new Command("Exit", Command.EXIT, 2);    Alert content;    Display display;    Thread thread;    String[] connections;    boolean done;    String smsPort;    MessageConnection smsconn;    Message msg;    Displayable resumeScreen;    public SMSReceive() {        smsPort = getAppProperty("SMS-Port");        display = Display.getDisplay(this);        content = new Alert("SMS Receive");        content.setTimeout(Alert.FOREVER);        content.addCommand(exitCommand);        content.setCommandListener(this);        content.setString("Receiving...");                resumeScreen = content;    }    public void startApp() {	    String smsConnection = "sms://:" + smsPort;        if (smsconn == null) {            try {                smsconn = (MessageConnection) Connector.open(smsConnection);                smsconn.setMessageListener(this);            } catch (IOException ioe) {                ioe.printStackTrace();            }        }        connections = PushRegistry.listConnections(true);        if (connections == null || connections.length == 0) {            content.setString("等待短信 " + smsPort + "...");        }        done = false;        thread = new Thread(this);        thread.start();        display.setCurrent(resumeScreen);    }    public void notifyIncomingMessage(MessageConnection conn) {        if (thread == null) {            done = false;            thread = new Thread(this);            thread.start();        }    }    public void run() {		            try {            msg = smsconn.receive();            if (msg != null && msg instanceof TextMessage) {                String address = msg.getAddress();                 content.setTitle("From: " + address);                content.setString(((TextMessage)msg).getPayloadText());                display.setCurrent(content);            }        } catch (IOException e) {        }    }    public void pauseApp() {        done = true;        thread = null;        resumeScreen = display.getCurrent();    }    public void destroyApp(boolean unconditional) {        done = true;         thread = null;        if (smsconn != null) {            try {                smsconn.close();            } catch (IOException e) {            }        }    }	public void commandAction(Command c, Displayable s) {        try {            if (c == exitCommand || c == Alert.DISMISS_COMMAND) {                destroyApp(false);                notifyDestroyed();            }        } catch (Exception ex) {            ex.printStackTrace();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -