J2ME SMS 发短信抛出异常:not allowed to send,这个问题是手机设置的问题还是程序?我的代码如下:
String address = null;
MessageConnection smsconn = null;
int size = phoneNumber.size();//phoneNumber是一个保存电话号码的Vector
int retValue = size;
if (size == 0) {
RMSDebugger.getInstance().printDebugger("SMS Message:(size == 0)");
return 0;
}
RMSDebugger.getInstance().printDebugger("SMS message=" + message);
for (int i = 0; i < size; i++) {
try {
// /address=Config.IS_LG_KP500?"sms://+86":"sms://";
address = "sms://";
address += (String) phoneNumber.elementAt(i);// 不加端口,直接发到好友的手机的收件箱中
smsconn = (MessageConnection) Connector.open(address);
RMSDebugger.getInstance().printDebugger("SMS address=" + address);
TextMessage txtmessage = (TextMessage) smsconn.newMessage(MessageConnection.TEXT_MESSAGE);
txtmessage.setAddress(address);
txtmessage.setPayloadText(message);
smsconn.send(txtmessage);
// 成功发送,那么说明这个邀请成功
} catch (Exception t) {
System.out.println("Send caught: ");
t.printStackTrace();
// 出现异常,说明有一条发送失败
retValue--;
} finally {
if (smsconn != null) {
try {
smsconn.close();
} catch (IOException ioe) {
System.out.println("Closing connection caught: ");
ioe.printStackTrace();
}
}
}
}
return retValue;
------解决方法--------------------------------------------------------
sim卡有余额么