解决接收短信的错误

时间:2011-09-14 08:05:11

标签: java-me sms

当两台设备收到短信时,将短信从设备发送到另一台设备 我在源代码中没有发现任何错误 请帮帮我 注:
这是发送源代码:

try {
String addr = "sms://" + txt_number.getString()+":1234";
MessageConnection conn = (MessageConnection) Connector.open(addr);
TextMessage msg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setPayloadText(txtSMS.getString());
conn.send(msg);
conn.close();
} catch (IOException ex) {  ex.printStackTrace();  }
<blink>and this is receive opretion .this opration support by a thread <blink>
public void run() {
String addr="sms://:1234";
Message msg=null;
try {
conn = (MessageConnection) Connector.open(addr);
while(true)
{               
msg=conn.receive();
String mSenderAddress = msg.getAddress();
if (msg instanceof TextMessage) {
String msgTReceived = ((TextMessage)msg).getPayloadText();
Analize_TEXT_message(mSenderAddress,msgTReceived);
}
}
} catch (IOException ex) {
ex.printStackTrace();
}
}

2 个答案:

答案 0 :(得分:0)

发送短信时删除端口号。

答案 1 :(得分:0)

String addr = "sms://" + txt_number.getString()+":1234";

应该是

String addr = "sms://" + txt_number.getString()+1234;

端口号应该没有任何引号。