我正在尝试制作一个J2ME应用程序以发送和接收文本消息.我已经完成了发送部分的操作,但是我无法收到任何消息.
I am trying to make a J2ME application to SEND and RECEIVE text messages. I'm done with the sending part of it but I am not able to receive any message..
下面是我为了接收短信而尝试的内容;
Below is what I tried in order to receive text message;
try { MessageConnection conn = (MessageConnection) Connector.open("sms://:50001"); conn.setMessageListener(new MessageListener() { public void notifyIncomingMessage(MessageConnection conn) { try { Message msg; msg = conn.receive(); if (msg instanceof TextMessage) { TextMessage tmsg = (TextMessage) msg; stringItem.setText("Msg: " + tmsg.getPayloadText()); System.out.println(tmsg.getPayloadText()); } // else if(msg instanceof BinaryMessage) { // ..... // } else { // ...... // } } catch (IOException ex) { ex.printStackTrace(); } finally { try { conn.close(); } catch (IOException ex) { ex.printStackTrace(); } } } }); } catch (Exception e1) { System.out.println(e1); }但是这不起作用...也没有错误显示...我在做什么错?...我们可以使用J2ME接收消息吗?
But this is not working...No errors are showing up either...what is that I am doing wrong?...Can we receive message using J2ME?
发送消息的代码:(已更新)
MessageConnection conn = (MessageConnection) Connector.open("sms://:50001"); TextMessage tmsg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE); tmsg.setPayloadText(message); tmsg.setAddress("sms://" + number); conn.send();我同时具有两种不同形式的send和receive函数.我所做的就是在两个不同的手机中安装并启动该应用程序,将消息从一个手机发送到另一个手机,然后在另一个手机中接收.
I have both the send and receive functions in two different forms. What I did is to install and start the application in two different mobiles, send a message from one mobile to the other and receive in the other.
消息已成功发送和接收,但未在应用程序中发送和接收.该消息将转到另一部手机的收件箱.
The message is sent and received successfully, but not in the application. The message goes to the inbox of the other mobile.
我该怎么办?
推荐答案尝试使用5000端口号.
try 5000 port no.
某些手机将此端口用作短信监听器
some phone have this port as sms listener
更多推荐
使用J2ME接收短信
发布评论