下面的代碼工作:J2ME手機短信發送權限N85壓制安全警告
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不會讓我發發短信沒有我按短信確認短信發送安全警告。我想實現的目的是能夠通過給予應用更高的權限來編程式地繞過這種安全措施?我怎麼做? 我只是不希望下次按下發送按鈕時彈出此安全通知。 我試圖設置API權限的NetBeans JAD和補充這些:
javax.microedition.io.Connector.sms
javax.wireless.messaging.sms.send
但是,這是不夠的,繞過它。任何想法的人? 而我不想使用QT,所以請不要在此建議!
感謝您的回覆mr_lou,這非常有幫助! – KopetePanda 2013-02-20 06:36:04
畢竟我不得不使用QT .. Java有太多限制! – KopetePanda 2013-02-21 07:00:26
非常真實。這絕對是開發人員快速接受Android並離開JavaME的原因之一。 – 2013-02-21 12:00:58