J2ME SMS IOException
我正在尝试向手机发送短信,但收到错误消息“
由于未知原因而无法发送”。 -java.io.IOException
import javax.microedition.io.Connector;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.*;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;
public class Midlet extends MIDlet {
Form form = new Form("Form");
Display display;
public void startApp()
{
display = Display.getDisplay(this);
display.setCurrent(form);
sendSMS("Hello from j2me");
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
private void sendSMS(String s) {
String destination = "+12234567890";
String addr = "sms://" + destination;
out("Setting up message");
MessageConnection sender = null;
try
{
try
{
sender = (MessageConnection) Connector.open(addr);
TextMessage msg = (TextMessage) sender.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setPayloadText(s);
out("sending");
sender.send(msg);
out("sent successfully");
}
catch (Exception ex)
{
out("Error1:" + ex.getMessage() + " : " + ex.toString() + "\n\n");
}
finally
{
sender.close();
}
}
catch (Exception ex) {
//handle exception
out("Error2:" + ex.getMessage() + " : " + ex.toString() + "\n\n");
}
}
private void out(String str)
{
form.append(str + "\n");
}
}
I am trying to send a text message to a phone and I get an error
Fail to send because of unknown reason. -java.io.IOException
import javax.microedition.io.Connector;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.*;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;
public class Midlet extends MIDlet {
Form form = new Form("Form");
Display display;
public void startApp()
{
display = Display.getDisplay(this);
display.setCurrent(form);
sendSMS("Hello from j2me");
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
private void sendSMS(String s) {
String destination = "+12234567890";
String addr = "sms://" + destination;
out("Setting up message");
MessageConnection sender = null;
try
{
try
{
sender = (MessageConnection) Connector.open(addr);
TextMessage msg = (TextMessage) sender.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setPayloadText(s);
out("sending");
sender.send(msg);
out("sent successfully");
}
catch (Exception ex)
{
out("Error1:" + ex.getMessage() + " : " + ex.toString() + "\n\n");
}
finally
{
sender.close();
}
}
catch (Exception ex) {
//handle exception
out("Error2:" + ex.getMessage() + " : " + ex.toString() + "\n\n");
}
}
private void out(String str)
{
form.append(str + "\n");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你给你的jad添加权限了吗?
MIDlet 权限:javax.microedition.io.Connector.sms、javax.wireless.messaging.sms.send
Did you add permissions to your jad?
MIDlet-Permissions: javax.microedition.io.Connector.sms,javax.wireless.messaging.sms.send
各种原因:
SecurityException
)All sorts of reasons:
SecurityException
)