📄 smsreceive.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 + -