我需要帮助。
我创建了一个简单的应用程序,用于侦听传入的短信,当短信到达并显示“OFF”时,设备应该关闭。
应用程序打开但在收到带有“关闭”字样的短信后无法关闭设备
我不知道我做错了什么。这是我的代码:
new Thread() { //A new thread is created and surrounds the code
public void run() {
try {
DatagramConnection _dc =
(DatagramConnection)Connector.open("sms://"); //A DatagramConnection is created to listen for any incoming sms's.
for(;;) { //'For-Loop' used to listen continously for incoming sms's
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
_dc.receive(d); //The sms is received
byte[] bytes = d.getData();
String msg = new String(bytes); //The body of the sms is put on a string.
if (msg == ("OFF") {
Device.requestPowerOff(false); //The device is shut down
}
}
} catch (NullPointerException me) { //NullPointerException caught
me.printStackTrace();
} catch (IOException io) {
io.printStackTrace();
}
}
};
当我在没有线程的情况下运行应用程序时,它会冻结手机。
请帮助,我已经尝试过,但我似乎无法做到这一点。