下面的代码有效:
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.wireless.messaging.*;
/**
* @author Panda
*/
public class Midlet extends MIDlet implements CommandListener {
Display display;
private TextField toWhom;
private TextField message;
private Alert alert;
private Command send,exit;
MessageConnection clientConn;
private Form compose;
TextMessage textmessage;
public void startApp() {
display=Display.getDisplay(this);
compose=new Form("Compose Message");
toWhom=new TextField("To","",10,TextField.PHONENUMBER);
message=new TextField("Message","",600,TextField.ANY);
send=new Command("Send",Command.BACK,0);
exit=new Command("Exit",Command.SCREEN,5);
compose.append(toWhom);
compose.append(message);
compose.addCommand(send);
compose.addCommand(exit);
compose.setCommandListener(this);
display.setCurrent(compose);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void commandAction(Command cmd,Displayable disp) {
if(cmd==exit) {
destroyApp(false);
}
if(cmd==send) {
String mno=toWhom.getString();
String msg=message.getString();
if(mno.equals("")) {
alert = new Alert("Alert");
alert.setString("Enter Mobile Number!!!");
alert.setTimeout(2000);
display.setCurrent(alert);
}
else {
try {
clientConn=(MessageConnection)Connector.open("sms://"+mno);
}
catch(Exception e) {
alert = new Alert("Alert");
alert.setString("Unable to connect to Station because of network problem");
alert.setTimeout(2000);
display.setCurrent(alert);
}
try {
textmessage = (TextMessage) clientConn.newMessage(MessageConnection.TEXT_MESSAGE);
textmessage.setAddress("sms://"+mno);
textmessage.setPayloadText(msg);
clientConn.send(textmessage);
}
catch(Exception e)
{
alert=new Alert("Alert","",null,AlertType.INFO);
alert.setTimeout(Alert.FOREVER);
alert.setString(e.getMessage());
display.setCurrent(alert);
}
}
}
}
}
我可以使用这个 midlet 发送短信,但唯一的问题是我的手机诺基亚 n85 不会让我在没有我在短信发送安全警告上按 OK 的情况下发送信息。我想要实现的是能够通过赋予应用程序更高的权限以编程方式绕过此安全措施?我怎么做?我只是不希望下次按下发送按钮时弹出此安全通知。我试图在 Netbeans 中为 JAD 设置 API 权限并添加了这些:
javax.microedition.io.Connector.sms
javax.wireless.messaging.sms.send
但这还不足以绕过它。任何想法任何人?而且我不想使用QT,所以请不要在这里建议!